How to load an ajax (jquery) request response progressively without waiting for it to finish?

前端 未结 4 2049
走了就别回头了
走了就别回头了 2020-12-06 08:28

I want to make a form that will use jquery to submit a list of keyword to a php file, this file could take a lot of time to load depending on the size of the keywords list.<

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-06 08:57

    Indeed there is a way. With plain old xmlhttpobjects I monitored the readyState. Ready state 4 means the request has ended. Ready state 3 means I can get some of the output and wait for more:

    request.onreadystatechange=function()
    {
        switch(request.readyState)
        {
            case 4:
                console.log("all good things come to an end");
            break;
            case 3:
                console.log("o, hai!" + request.responseText);
            break;
        }
    }
    

    I believe you can achieve the same using jQuery: jQuery: Is req.readyState == 3 possible?

提交回复
热议问题