本文介紹了jquery嵌套ajax調(diào)用格式化的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
限時(shí)送ChatGPT賬號(hào)..
我需要根據(jù)上一次調(diào)用的數(shù)據(jù)連續(xù)進(jìn)行 6 次 ajax 調(diào)用.我將每個(gè)調(diào)用嵌套在上一個(gè)調(diào)用的成功中.我的問(wèn)題是有什么好的方法來(lái)格式化代碼,這樣它就不會(huì)在我的編輯器中出現(xiàn)一百萬(wàn)行?
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
}
})
}
})
})
}
})
忽略括號(hào),語(yǔ)法對(duì)于這個(gè)問(wèn)題并不重要.
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();
}
});
}
這篇關(guān)于jquery嵌套ajax調(diào)用格式化的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!