[英]Calling a Success script if @Ajax call succeed
I have the following javascript which contains an ajax call:- 我有以下包含ajax调用的javascript:-
$.ajax({
type: "POST",
url: '@Url.Action("DeleteSelected"),
data: { ids: boxData.join(",") }
})
});
but is there a way to call a javaScript function is the above Ajax call succeed? 但是有没有一种方法可以调用javaScript函数,上述Ajax调用是否成功? Thanks
谢谢
function mySuccessFunction() {
alert('success');
}
$.ajax({
type: "POST",
url: '@Url.Action("DeleteSelected")',
data: {
ids: boxData.join(",")
},
success: function(data) {
// your code if AJAX call finished successfully
// call your function that already loaded from here:
mySuccessFunction();
// you can also process returned data here
}
});
You have three particular handlers you can use to process information returned with AJAX, .success(), .done(), and .fail(). 您可以使用三个特定的处理程序来处理AJAX,.success()、. done()和.fail()返回的信息。 With these methods, your code might look something like this:
使用这些方法,您的代码可能看起来像这样:
$.ajax({
type: "POST",
url: '@Url.Action("DeleteSelected"),
data: { ids: boxData.join(",") }
}).success(function(data) {
// This callback is executed ONLY on successful AJAX call.
var returnedJSON = data; // The information returned by the server
yourSuccessFunction();
}).done(function() {
// This callback is ALWAYS executed once the AJAX is complete
yourDoneFunction();
}).fail(function() {
// This callback is executed ONLY on failed AJAX call.
});
Also see: jQuery AJAX Documentation 另请参阅: jQuery AJAX文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.