我正在使用web服務刪除某些記錄。 jquery ajax請求是在超鏈接的onclick中寫入的。當我執行腳本時,使用螢火蟲一行一行,它被刪除,否則它不是。有人遇到過這種情況嗎?請幫助如何在導航到其他頁面之前確保函數完全執行?
代碼示例:
$(".target").click(function() {
func(); //This function should be executed completely before navigating to another page
});
var func = function() {
var items = $("#flag").find('td input.itemClass');
id = items[0].value;
var status = items[1].value;
var type = items[2].value;
var params = '{' +
'ID:"' + id + '" ,Type:"' + type + '" ,Status:"' + status + '"}';
$.ajax({
type: "POST",
url: "WebMethodService.asmx/DeleteItem",
data: params,
//contentType: "plain/text",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$("#deleteNotificationMessage").val("Item has been removed"); // keep a separate label to display this message
}
//Event that'll be fired on Success
});
}
你使用asp.net mvc 3嗎? – Thulasiram