我正在开发一个需要多个 ajax 请求的应用程序,这样只有在单击并返回其响应Option2
时才可用。Button2
同样,Option3
只有在Button3
被点击时才可用。以下是代码的一般结构。我正在php
&中构建应用程序mysql
。
$("#button1").click(function() {
$.ajax({
type: "POST",
url: "url-1",
data: { id: //some-id },
success: function(response) {
$('.menu-right').html(response);
$(".button2").click(function() { //button2 is created when the above response is printed as html
$.ajax({
type: "POST",
url: "url-2",
data: { id: this.id },
success: function(response) {
$('.menu-right-jump').html(response);
$('.button3').click(function() { ////button3 is created when the above response is printed as html
$.ajax({
type: "POST",
url: "url-3",
data: { id: this.id },
success: function(response) {
// some things to do
},
error: function(error) {
alert("Error");
}
});
});
},
error: function(error) {
alert("Error");
}
});
});
},
error: function(error) {
alert("Error");
}
});
});
目前,一切正常。该应用程序最多可供 10,000 名用户使用。我只是想知道是否有更好的方法/或我可以合并的任何可用框架。
另外:使用这种方式可能会出现什么问题以及清除这些问题的方法。