简体   繁体   English

使用JQuery发布请求并接收多个答案,可能吗?

[英]Post request with JQuery and receive multiple answers, possible?

I know how to do a post-request with jquery and get one response, but I wonder If I can post something with AJAX and then wait for multiple responses. 我知道如何使用jquery执行后请求并获得一个响应,但是我想知道是否可以使用AJAX发布某些内容,然后等待多个响应。

The idea behind it is that I have a progressbar (which I want to animate), so I need to get the status of the execution in my background code, which I called with AJAX. 其背后的想法是,我有一个进度条(我想对其进行动画处理),所以我需要在我用AJAX调用的后台代码中获取执行状态。

Is this possible? 这可能吗? I checked this . 我检查了这个 But it didn't help me. 但这并没有帮助我。

Thanks! 谢谢!

You can try to identify the status for ajax when this execute into your web page. 当它执行到您的网页中时,您可以尝试识别ajax的状态。 Example: 例:

<script type="text/javascript">

//in your DOM, CALL YOUR FUNCTION

    loading();

    //set an interval to stop de function if the ajax is ready and all elements are ready
    $load = {
        setInterval(function() {
            loading();
        }, 1000); //each one second this Interval was checked if the page is complety ready
    }

    function loading() {

        var x = document.readyState;
        switch (x) {
            case 'loading';
                //show, hide something or animate an toolbar before of 50%
            break;

            case 'interactive';
                 //show, hide something or animate an toolbar before of 70%
            break;

            case 'complete';
                //show, hide something
                //we clean the interval to sstop if is compete and show the toolbar in 100%
                clearInterval($load);
            break;
        }

    }

</script>

You can learn more about Ready State property here http://www.w3schools.com/jsref/prop_doc_readystate.asp 您可以在http://www.w3schools.com/jsref/prop_doc_readystate.asp上了解有关“就绪状态”属性的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM