如何加载AJAX(jQuery的)请求响应逐步无需等待它完成? [英] How to load an ajax (jquery) request response progressively without waiting for it to finish?
问题描述
我想要将使用jQuery的关键字列表提交给一个PHP文件格式,该文件可能需要大量的时间取决于关键字列表的大小来加载。
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.
我想要做的是加载PHP响应转换成实时股利或容器不使用内置页框。
What I want to do is to load the php response into a div or container in real time without using iframes.
我所知道的Ajax请求必须等待,直到请求不必响应访问之前完成,我需要访问即使还没有完成,所以我可以实时更新的进步响应。
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.
推荐答案
确实有一种方法。随着老式xmlhttpobjects我监视readyState的。就绪状态4表示请求已经结束。就绪状态3意味着我可以得到一些输出,并等待更多:
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;
}
}
我相信你可以实现使用jQuery相同的:<一href="http://stackoverflow.com/questions/287286/jquery-is-req-readystate-3-possible">http://stackoverflow.com/questions/287286/jquery-is-req-readystate-3-possible
这篇关于如何加载AJAX(jQuery的)请求响应逐步无需等待它完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!