嗯,我有这样的事情,加载HTML使用加载根文件的路径的相对路径,而不是源文件的路径
<html>
<head>
<script src="jquery.js" type="text/javascript"></script>
</head>
<body>
Loading your content...
</body>
<script type="text/javascript">
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)
{
$("body").html(xmlhttp.responseText);
}
};
xmlhttp.open("GET","../stats.phtml",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send();
</script>
</html>
而且它并没有找到加载的文件统计链接的任何外部文档。 phtml(javascript和css源代码),因为相对路径的路径是文档的路径,而不是加载文档的根路径。
我需要在AJAX上执行此操作(加载页面应在执行脚本时加载内容并在3秒后显示它),所以只需执行window.location ='../stats .phtml'3秒后不是一个好的解决方案。我还想保留已加载文档中的相关链接,而不是将其移至绝对路径。有什么建议么?
我目前正在尝试您的更新中的具体内容,它给我在Firefox中遇到的各种麻烦。看起来像pushstate和document.open并不能很好地协同工作。这是如何在Firefox中为你工作的? – gmustudent 2013-04-25 17:15:57
这是一年多以前,但我没有任何麻烦。查看https://developer.mozilla.org/en-US/docs/DOM/Manipulating_the_browser_history#The_pushState().C2.A0method(对不起,对于迟到的答案) – NotGaeL 2013-04-30 17:24:43