【发布时间】:2017-01-04 12:13:23
【问题描述】:
我有这个 JS:
$('.save').click(function(e){
var row = $(this).closest('tr');
var button = $(this);
var myParams = new Object();
myParams.id = row.find('.id').text();
myParams.data = row.find('.data').text();
myParams.descrizione = row.find('.descrizione').text();
myParams.movimento = row.find("select[name='tipo_mov']").val();
myParams.importo = row.find('.importo').text();
myParams.from = 'carta';
var params = JSON.stringify(myParams);
$.post( "edit_mov.php", params)
.done(function( data ) {
bootbox.alert("Movimento aggiornato correttamente");
button.toggle().prev('.edit').toggle();//ripristino il pulsante di edit;
row.removeClass('info').addClass('success').find('.tbe').attr('contenteditable', false).css('color','');
row.find('.tipo_mov').toggle();
setTimeout(function () {
row.removeClass('success');
}, 2000);
})
.fail(bootbox.alert("UPS! Something went wrong"));
});
这样做是为了使用 AJAX 请求更新表行。 负责更新的 PHP 页面将返回 200 或 500,具体取决于查询是否成功:
if($count==0){
http_response_code(500);
}else{
http_response_code(200);
}
如果我尝试使用将失败的查询,我的 JS 将仅在 .fail 中显示警报。 如果我尝试使用会成功的查询,那么我将同时看到警报(.done 和 .fail)。
我还尝试将 .done 替换为 .success buth,但结果相同。我做错了什么?
【问题讨论】:
标签: javascript jquery ajax