我想知道是否有适当的方法来防止ajax请求同时调用任意404/500错误(同步或异步)。
例如,一个包含一些行和列的简单html表,用来显示一个500-800人的列表,其中有一些数据。
前进的路:
伪码:
function createTableData(){
var selected;
var personIds;
//get personIds by selection and write them into table
object.executeJSONRequest(...,
{ _ts: new Date().getTime(),
input: selected
},function(data) {
// write result into table
// fill resourceIds with result param
},..);
getEvents(personIds);
getAttribtues(personIds);
getRoles(personIds);
calculateStuff(personIds);
}
function getEvents(personIds){
object.executeGetRequest('...',
{ _ts: new Date().getTime(),
ppl: personIds
},function(data) {
//add result to table
}
}
function getAttributes(personIds){...} //and so on..如果我在一行中调用所有这些方法,有时在加载属性时会出现随机错误,有时在加载角色时会出现随机错误,有时会很好地工作。
如果我将它们称为嵌套在每个ajax成功块中,如
function createTableData(){
object.executeJSONRequest(...
{ _ts: new Date().getTime(),
input: selected
},function(data) {
getEvents(..);
});
}
function getEvents(..){
object.executeGETRequest(...
{ _ts: new Date().getTime(),
input: selected
},function(data) {
getAttributes(..);
});
}
function getAttributes(..){ ...,function(data){ getRole(..)}); and so on一切都很好。如果我用这样的方法来解决
document.ajaxStart/Stop(function(){ //if table columns i expected are filled do next}我必须检查所有必要的表格列是否已经填充了数据。
有没有什么真正正确的解决办法我只是想不起来?(jQuery版本1.2 /IE V7-8 ^)
发布于 2013-10-17 12:48:01
“如果可能,更新jquery和ie版本”
首先,为什么要在单个进程中调用多个服务器调用。
如果将所有进程合并到一个请求和响应周期中,在java代码中完成所需的数据处理会更好,不要重复执行请求和响应。
任何方式都可以使用jquery,它返回ajax调用的状态。
$.post("url",function(result,status){{
if(status == success){
//continue....
}else{
alert("Sorry something went wrong");
}
}});就像这样,检查所有的请求是否成功完成。
我强烈建议您考虑将所有ajax调用合并到一个请求中。
https://stackoverflow.com/questions/19426634
复制相似问题