最好的答案是禁用鏈接,如果它是不活動的,在用戶嘗試點擊它之前(爲什麼讓它們嘗試?)。
jQuery(function($) { // make sure dom is ready
$.ajax({
url: url,
//dataType: 'JSONP', //might need this?
complete: function(xhr) { // use complete so it fires on error OR success
if(xhr.status == 200 || xhr.status == 304) {
$('#link').addClass('valid');
}
else {
$('#link').addClass('invalid').click(function() { return false; });
}
}
});
});
但是,如果你不希望調用,因爲那裏將是成千上萬的用戶在看每分鐘頁面...你
jQuery(function($) { // make sure dom is ready
$('#link').click(function() {
$.ajax({
url: url,
//dataType: 'JSONP', //might need this?
success: function() {
window.location = url;
},
error: function() {
// does this work with JSONP? be sure to check!
window.alert('could not connect');
}
}
});
});
你能詳細說一下嗎? –