开发者

send multiple responses on one ajax request and react on clientside

i would like to send responses to the client during an ajax request (imagine a file uplo开发者_C百科ad or something) and react on that responses on the clientside.

  1. send ajax request
  2. do lot of work on serverside and send information about that to the clientside
  3. during the serverside ist still doing lot of work do something on clientside like inform user about progress...

i hope this is understandable?

now how to do that? until now i am only able to react when the ajax request is complete.


You might try using multiple ajax requests and calling them sequentially using whatever callback facility is offered by the framework you're using. For example (jQuery):

function getData(){
    $.load(someUrl,onDataReceived)
}
function getMoreData(){
    $.load(someOtherUrl,onMoreDataReceived);
}
function onDataReceived(){
    // update your UI in a meaningful way so that the user knows things are happening
    getMoreData();
}
function onMoreDataReceived(){
    // update your UI again
    alert('Got Everything');
}
$(function(){ getData(); }); // start the process on page load

I believe it's possible to listen for "progress events", but I think those are limited to things like file uploads, etc.

Anyway, good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜