刷新后如何保持ajax加载! [英] how to keep ajax loaded after refreshing!!

查看:94
本文介绍了刷新后如何保持ajax加载!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!再次在这里有一个小问题!

我会直截了当!!

Hello everyone!! here again with a little problem!!

I will straightly go the point!!

<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		document.getElementById("test").innerHTML=xmlhttp.responseText;
		}
	  }
	xmlhttp.open("GET","info.php",true);
	xmlhttp.send();

}
</script>

</head>

<body>

<div id="test"><h2>This is where the new text will be displayed</h2></div>
<button type="button"  önClick="loadXMLDoc()">Change Content</button>


</body>
</html>


这是我在同一目录中的info.php文件!


And here is my info.php file in the same directory!!

echo "tarek";
?>


现在的问题是,当我单击按钮div会将我的结果更改为该PHP文件时,一切工作正常.但是,当我刷新页面时,它会返回到原始阶段!

刷新后,我想将其保存到info.php文件中.


Now the thing is that Everything is working fine when I click on the button the div is changing my result to that PHP file. But when I refresh the page it goes back in the original phase!!

I want to keep it to the info.php file after refresh!!!

推荐答案

记住,网络是无状态的.浏览器无法知道页面是第一次显示还是正在刷新,因此,除非另行通知,否则页面内容将被重置. Ajax调用带外,因此它不包含在原始输出中.如果要保留输出,则需要设置某种标志,该标志用于再次触发Ajax调用.
Remember that the web is stateless. There is no way for the browser to know whether the page is being displayed for the first time or being refreshed so, unless told otherwise, the page contents will be reset. The Ajax call is out of band so it is not included in the original output. If you want to keep the output you will need to set a flag of some sort that is used to trigger the Ajax call once again.


我知道,先生!我什至尝试了!但是不知何故,这是有问题的.我什至不知道怎么向你解释!!无论如何都值得一试..谢谢您的帮助!让我看看我该怎么办:-)
I know that sir!! I even tried that out!! But somehow there is something wrong. I don''t know even how to explain it to you!! anyway it was worth a try.. thank you for your help!! Let me see what can i do :-)


这篇关于刷新后如何保持ajax加载!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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