嗯,我有這樣的事情,加載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