所以,我有以下功能。單擊我發送一些數據通過AJAX到填充頁面,我張貼到我的分貝。這部分工作正常。但是,我需要刪除我的表中成功的數據庫插入行。我試圖使用.done(),但由於某種原因,它不會觸發。是否有觸發器,我需要執行另一個PHP頁面,讓這個腳本知道這是一個成功的操作?AJAX回調不會觸發
$(document).on('click', '.send', function() {
$(this).closest('tr').find('input:not(.ofrCode)').each(function(){
if ($(this).val() == '') {
$(this).parent().addClass('has-error');
}
});
if (!$(this).closest('tr').find('td').hasClass('has-error')) {
var code = $(this).closest('tr').find('.item').val();
$.ajax({
type: 'POST',
url: '/myPage.php',
data: {
'code' : code
},
dataType : 'json',
async: false
}).done(function() {
$(this).closest('tr').remove();
});
}
});
'async:false' ---你爲什麼需要這個? HTTP請求是否成功執行? – zerkms 2014-11-06 22:57:49
1)爲什麼'sync:false'和2)嘗試添加'.fail(function(data){console.log(「error」,data);})'看看它是否失敗 – elzi 2014-11-06 22:58:25
請注意,使用'.done )'async:false'從jQuery 1.8開始不推薦使用。 – Barmar 2014-11-06 23:02:37