Are there progress update events in jQuery ajax?

前端 未结 6 781
北海茫月
北海茫月 2020-12-31 16:22

i have long running task that gets called using jquery ajax. i am using the block ui plugin to show \"loading\". is there anyway i can send progress messages back to the

6条回答
  •  抹茶落季
    2020-12-31 16:37

    What you are trying to do is something similar to Comet. Traditional ("non-comet") webservers are not designed for this kind of transaction model and is therefore not a desired solution.

    My suggestion is to break up the processing in one client request per data source:

    function loadData() {
       // Each call passes callback(id) as a success handler
       fireAsynchronousRequest("source1");
       fireAsynchronousRequest("source2");
       fireAsynchronousRequest("source3");
    }
    
    function callback(var source) {
       if (source == "source1") {
           updateStatus("Source 1 loaded");
       }
       else if (source == "source2") {
           updateStatus("Source 2 loaded");
       }
    }
    

    This is an example of an asynchronous solution. You can implement state handling in callback() if you need it to be synchronous.

提交回复
热议问题