Reputation: 9285
I have a div:
<div id="content"></div>
And when the page is loaded i call a .load()
. This load takes around 10 minutes to finish and during the execution its PHP file return some information telling about the execution status, something like Linux loading. I want do put this information inside the div #content
dynamically, but .load()
is putting only at the end of the execution. Someone can help me please to do this?
The .load()
call:
$("#content").load("/admin/ajax/analyse.php");
Upvotes: 2
Views: 7956
Reputation: 91467
jQuery's ajax interface does not provide a way to get progress updates for a response (even though it claims to be a superset of the browser's native XMLHttpRequest
object). Apparantly, such a use case is inconceivable to the jQuery developers:
No
onreadystatechange
mechanism is provided, however, sincesuccess
,error
,complete
andstatusCode
cover all conceivable requirements.
By using the an XMLHttpRequest
directly, you can read the current progress of a response in an onreadystatechange
event handler:
var xhr = new XMLHttpRequest();
xhr.open("GET", "/admin/ajax/analyse.php", true);
xhr.onreadystatechange = function receiveUpdate(e) {
$("#content").html(this.responseText);
}
xhr.send();
This works in the latest versions of most browsers including IE 10, Chrome, and Firefox.
Demos:
Upvotes: 3
Reputation: 12985
This is just an idea that you would have to flush out ...
On the server,
On the server also:
On the client side,
That should work for you.
Upvotes: 0
Reputation: 4257
There are a couple of ways to address this, but all of them will require server-side changes. One solution (which I think best fits how you are imagining this to work) is long polling.
See this quesiton on long polling with PHP and jQuery.
Upvotes: 0