在本地起了个 sever,用于ajax跟后台交互。写完页面之后,在谷歌,火狐,360相继测试一切正常。但是要求最低兼容IE8,最后就在IE8下进行测试,发现:页面根本没有加载任何后台数据。于是乎,费尽力气在IE下调试JS。奈何,JS真难调。此时,对IE8的愤怒已经到了极点。但是还得找问题。最后发现是因为,正在我JS代码中有这么一段:
var basePath="";
if (window.location.href.indexOf("dd-")>0) {
basePath=window.location.origin+"/"+window.location.pathname.split("/")[1]+"/";
console.log(basePath);
} else{
basePath=window.location.origin+"/";
console.log(basePath);
}
这个basePath是我在 发ajax请求的地址
原理是因为IE8对location.origin有兼容性。
最后我将代码改变成了:
if (window.location.href.indexOf("dd-")>0) {
// 兼容ie
if (window["context"] == undefined) {
if (!window.location.origin) {
window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
}
window["context"] = location.origin+"/V6.0";
}
basePath=window.location.origin+"/"+window.location.pathname.split("/")[1]+"/";
} else{
basePath=window.location.origin+"/";
}
问题解决了。心情好到炸。。。。。。。