将整个页面替换为ajax加载页面的内容 [英] Replace entire page with contents of an ajax loaded page

查看:126
本文介绍了将整个页面替换为ajax加载页面的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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.

我有一个使用很多ajax调用的webapp.问题是,如果用户在这样的页面上并且徘徊了足够长的时间以致触发了会话超时,则该应用使会话无效,并且下次用户与显示的页面进行交互时,系统将返回首页,要求他们进行操作.再次登录.当然-主页显示为嵌入在他们最后查看的任何页面中,而不是替换它.我可以在主页中放入什么内容,以确保它始终替换整个页面,而不必检查每个ajax调用是否返回了主页?

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?

推荐答案

我不确定您对本次会议的看法.但是,如果您只想使用ajax重新加载页面内容,则应该可以:

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);
 }
});

这篇关于将整个页面替换为ajax加载页面的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆