[英]Ajax call no error but does not work
在這里我的Ajax調用,它不會產生任何錯誤,但它不會調用php文件(我可以在我的chrome的網絡選項卡中看到它,當我在javascript控制台中調用它時,它會按預期返回false:
function submitData() {
$('#sortable2').sortable({
axis: 'y',
update: function(event, ui) {
var data = $(this).sortable('serialize');
$.ajax({
data: data,
type: 'POST',
url: './post_occupation_data.php'
});
}
});
return false;
}
謝謝
嘗試此代碼,並檢查您是否收到警報消息..如果404警告消息,請檢查您的URL
function submitData() {
$('#sortable2').sortable({
axis: 'y',
update: function(event, ui) {
var data = $(this).sortable('serialize');
$.ajax({
data: data,
type: 'POST',
url: './post_occupation_data.php',
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
},
success: function(result){
alert(result);
}
});
}
});
return false;
}
嘗試將參數字符串化,如下所示
data: JSON.stringify(data)
還要在ajax調用中添加以下參數
contentType: "application/json; charset=utf-8",
dataType: "json",
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.