Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace entire page with contents of an ajax loaded page

Tags:

jquery

ajax

I'm using JQuery and I am trying to find a means of replacing the entire page with the contents of an ajax load. I've found answers that suggest how to do it from the loading page, but I would like to do it from the loaded page if possible.

I have a webapp that uses a lot of ajax calls. The problem is if the user is at such a page and wanders off for long enough that the session timeout is triggered, then the app invalidates the session and the next time the user interacts with the displayed page the system returns the home page asking them to log in again. Of course - the home page appears embedded in whatever page they were last looking at rather than replacing it. Is there anything I can put in my homepage that will ensure it always replaces the entire page rather than having to check every ajax call for the home page being returned?

like image 342
user497087 Avatar asked Jan 21 '13 07:01

user497087


1 Answers

I'm not sure what you are getting at with the session. But if you would just like to reload the page contents using ajax, this should work:

$.ajax({
 type:'post',
 data:{},
 url:'your url',
 dataType:'html',
 success:function(response){
   $('body').html(response);
 }
});
like image 117
Ethan Avatar answered Sep 22 '22 01:09

Ethan