本文介紹了jquery嵌套ajax調用格式化的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我需要根據上一次調用的數據連續進行 6 次 ajax 調用.我將每個調用嵌套在上一個調用的成功中.我的問題是有什么好的方法來格式化代碼,這樣它就不會在我的編輯器中出現一百萬行?
I have a requirement to make 6 ajax calls in succession based on data from the previous call. I am nesting each call in the success of the previous call. my question is what are some good ways to format the code so that it doesnt end up a million rows across my editor?
$.ajax({
type: "POST",
url: "someScript/someScript.php",
data: form + "&func=build",
success: function (result) {
if (result == "ok")
{
$.ajax({
type: "POST",
url: "someScript/someScript.php",
data: form + "&func=someOtherFunc",
success: function (result) {
if (result == "ok")
{
$.ajax({
type: "POST",
url: "someScript/someScript.php",
data: form + "&func=someOtherFunc",
success: function (result) {
if (result == "ok")
{
.....and so on
}
})
}
})
})
}
})
忽略括號,語法對于這個問題并不重要.
ignore brackets, syntax isnt important for this question.
推薦答案
你可以這樣做
function ajaxCall1(){
$.ajax({
success: function(){
ajaxCall2();
}
});
}
function ajaxCall2(){
$.ajax({
success: function(){
ajaxCall3();
}
});
}
function ajaxCall3(){
$.ajax({
success: function(){
ajaxCall4();
}
});
}
這篇關于jquery嵌套ajax調用格式化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!