one ui ajax 提交,javascript - UI unresponsive during AJAX calls - Stack Overflow

I've had similar problems working heavily with SharePoint web services - you often need to pull data from multiple sources to generate input for a single process.

To solve it I embedded this kind of functionality into my AJAX abstraction library. You can easily define a request which will trigger a set of handlers when complete. However each request can be defined with multiple http calls. Here's the component (and detailed documentation):

This simple example creates one request with three calls and then passes that information, in the call order, to a single handler:

// The handler function

function AddUp(Nums) { alert(Nums[1] + Nums[2] + Nums[3]) };

// Create the pool

myPool = DP_AJAX.createPool();

// Create the request

myRequest = DP_AJAX.createRequest(AddUp);

// Add the calls to the request

myRequest.addCall("GET", "http://www.mysite.com/Add.htm", [5,10]);

myRequest.addCall("GET", "http://www.mysite.com/Add.htm", [4,6]);

myRequest.addCall("GET", "http://www.mysite.com/Add.htm", [7,13]);

// Add the request to the pool

myPool.addRequest(myRequest);

Note that unlike many of the other solutions provided this method does not force single threading of the calls being made - each will still run as quickly (or as slowly) as the environment allows but the single handler will only be called when all are complete. It also supports the setting of timeout values and retry attempts if your service is a little flakey.

In your case you could make a single request (or group related requests - for example a quick "most needed" request and a longer-running "nice to have" request) to call all your data and display it all at the same time (or in chunks if multiple requests) when complete. You can also specifically set the number of background objects/threads to utilize which might help with your performance issues.

I've found it insanely useful (and incredibly simple to understand from a code perspective). No more chaining, no more counting calls and saving output. Just "set it and forget it".

Oh - concerning your lockups - are you, by any chance, testing this on a local development platform (running the requests against a server on the same machine as the browser)? If so it may simply be that the machine itself is working on your requests and not at all indicative of an actual browser issue.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值