【发布时间】:2012-09-21 10:06:43
【问题描述】:
我现在正在使用 Ajax,我有这段代码:
<script type="text/javascript">
function load(file,container)
{
var xmlhttp, newhash = '';
if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest();}
if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
xmlhttp.onreadystatechange= function (){
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{ document.getElementById(container).innerHTML=xmlhttp.responseText;
} else {
document.getElementById(container).innerHTML='<div style="padding:10px"> <p>Please upgrade your web browser to support modern technology.</p></div>';
}
}
xmlhttp.open("GET",file,true);
xmlhttp.send(null);
}
</script>
<script type="text/javascript" src="jquery.js"></script>
<ul>
<li><a href="#" onclick="load('home.php','ajax');return false;">Home</a><li/>
</ul>
<div id="ajax">
</div>
对不起,这是我的第一篇文章,但我真正担心的是,页面可以加载,但是当我刷新页面时,页面就会消失。我试图在 url 上放一个哈希,但它仍然不起作用。
【问题讨论】:
-
什么问题?我检查了你的代码,它工作正常。
-
如果您已经使用 jquery,您可以使用 jquery load api.jquery.com/load 更轻松、更简洁地做到这一点
-
我会检查它@hsalama..感谢您的反馈!!!!我很感激。
标签: php javascript ajax