Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

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

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.

What I want to do is to load the php response into a div or container in real time without using iframes.

All the ajax request I know have to wait until the request has finished before having access to the response, I need to get access to that response even when it hasn't finished so I can update the progress in real time.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...