Show progress during a long Ajax call

前端 未结 1 1446
遥遥无期
遥遥无期 2021-02-10 02:27

I have a simple web site (http://www.kousenit.com/twitterfollowervalue) that computes a quantity based on a person\'s Twitter followers. Since the Twitter API only returns foll

相关标签:
1条回答
  • 2021-02-10 03:08

    For more-or-less-accurate progress reporting you have two alternatives:

    • Keep the server telling you its progress
    • Keep the client (browser) asking the server about its progress

    Keeping the server telling you the progress would be kind of easy to implement. You can, instead of calling the Ajax.Updater, create an iframe element and modify the server to, for each iteration, dump a response with some javascript to trigger showing the progress on the browser, and to flush that response. Like that, the browser will execute the javascript and keep waiting until the response finishes, so the user will see the progress indicator moving up until everything's completed.

    Other approaches are available for the server to tell you about the operation's progress. You can Bing/Google about Comet servers.

    As for getting the browser to periodically ask about the operation's progress, you can either return some token to the browser for each iteration that the browser would check to see if it's the final result or if it should pass it on to the server so the server keeps hitting twitter for the next result set, or somehow keep a state (if you have session state support, that might do it) in your server that is updated in each iteration and that can be polled on a separate request.

    I hope the suggestions help.

    0 讨论(0)
提交回复
热议问题