Reputation:
I need to initiate a reload from the server side(PHP) durring and AJAX call. How do I do this. I honestly don't think it is supported.
My current method is to use the PHP header() function and capture it as responseText from the AJAX call and then do an innerHTML add.
However it is not a proper reload in my book as it doen not intiate the onload function. It also seems to to be contrived and not a "clean" solution.
Upvotes: 1
Views: 1296
Reputation: 1534
The only way to reload the entire page is to change the window.location
. You can't do that from the server. Every action must be initiated from the client - that's fundamental of restful protocols like HTTP.
However, your server could send back the entire document, and you could then 'pick' the portion to replace. jQuery allows this with the load function.
For instance this would reload the BODY:
$('body').load('ajax/page.html body');
Upvotes: 0
Reputation: 6588
There is a pattern that uses AJAX to create a PUSH-alike application. I don't know the real name of the paradigm, nor a good implementation, but this is basically how it works:
So there is always a "hanging" connection, and as soon as the server wants to respond, the client immediately creates a new one that hangs again.
Upvotes: 1
Reputation: 10582
Send a command/flag back to your Ajax handler to make it call the following JavaScript method in the page:
window.location.reload();
Upvotes: 2