<分区>
Possible Duplicate:
Chrome: Disable same origin policy
关于我的问题的一些背景信息:
- 为画廊编写 JavaScript 文件;从 xml 中提取数据 文件,here .
- 使用 XMLHttpRequest() 加载 DOM 对象,使用异步加载。
- 使用 DOMParser 解析 responseText 以生成 DOM 对象。
- 在 FireFox 上工作,在 Chrome 上失败。
编辑(请阅读):
After using console.log, it seems that Chrome is reporting a Cross-Origin Issue:
- Failed to load resource file: ./Gallery/dropdown_style.css
- XMLHttpRequest cannot load file: ./Gallery/gallery_info.xml. Cross origin requests are only supported for HTTP.
- NodeList[0]
- length: 0
- Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101
- Failed to load resource ./Gallery/Pictures/bg_one.jpg
Now my questions are:
- How do I fix this on the local level (offline)?
- Will this still be a problem even if I upload all the files to the same server?
- If so, what's the solution for that as well (online)?
现在 DOM 对象通过了,大概在 Firefox 和 Chrome 上都是正确的。 并在以下代码中:
window.alert(xmlDoc.getElementsByTagName("pic"));
它返回“HTML Collection”的响应,或者在 Chrome 中返回“NodeList”。但是当我在 Chrome 中询问该 NodeList 的长度时,它返回 0,这意味着 NodeList 的格式不正确,或者与我预期的不同。
在 FireFox 中,长度将返回值 2,这正是我想要的。
这是我的源代码,没有多余的行话:
var elemPic = [];
function initGallery(xmlFName){
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", xmlFName, true);
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4){ //since it's offline and local, don't check status == 200
//use a DOMParser, which is in a different file
myCallBack(parseXml(xmlhttp.responseText));
}
}
xmlhttp.send();
}
function myCallBack(xmlDoc){
//window.alert(xmlDoc);
elemPic = xmlDoc.getElementsByTagName("pic");
//window.alert(elemPic);
for(var i = 0; i < elemPic.length; i++){
//whats the source path?
var src = elemPic[i].getElementsByTagName('src')[0].childNodes[0].nodeValue;
window.alert(src);
}
}
这是我的整个源文件夹,如果你想看的话:Source Folder
我不确定这是哪个问题:
- DOM xml 对象已损坏
- 节点列表已损坏
- getElementsByTagName() 的总体 Chrome 问题
- 其他
如果你们能帮助我确定问题的确切根源和解决方案,那么我将不胜感激。