【发布时间】:2014-03-06 19:05:39
【问题描述】:
我需要根据上一次调用的数据连续进行 6 次 ajax 调用。我将每个调用嵌套在上一个调用的成功中。我的问题是有什么好的方法来格式化代码,这样它就不会在我的编辑器中结束一百万行?
$.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
}
})
}
})
})
}
})
忽略括号,语法对于这个问题并不重要。
【问题讨论】:
-
为什么不在函数中封装 ajax 调用?
-
创建一个一次性完成所有这些工作的 php 脚本?
标签: jquery ajax formatting