本地HTML文件AJAX调用和jQuery愁楚 [英] Local html file AJAX Call and jQuery Woes
问题描述
我正在使用jQuery和一些XML文件的网站的离线版本。我运行到jQuery的一个问题,当我做了$就调用一个xml文件的jQuery抛出一个错误。
当我看到错误,我可以告诉其加载XML文件,因为它在错误的responceText财产。它接缝就很好地工作在Firefox。
这是我的电话看起来
$。阿贾克斯({
键入:GET,
网址:模块/+的moduleId +/ModuleContent.xml
数据类型:XML,
成功:函数(X){XML = X;的processXML(); },
错误:函数(X){警报(x.responceText); }
});
在我这运行的Web服务器上工作得很好。它只有当我运行它从文件自身,当我有这个问题。
我如何使这项工作在IE任何想法?
编辑:我找到了答案,我的问题。 这里
从链接的是,OP贴有答案了:
在本地加载XML文件,例如一个 的CD-ROM等,接收到的数据 Internet Explorer的是纯文本,而不是 文/ XML。在这种情况下,使用 dataType参数加载XML 文件为文本,并分析返回 在更迭函数中的数据。
$。阿贾克斯({
网址:data.xml的,
数据类型:($ .browser.msie)? 文:XML,
成功:功能(数据){
VAR XML;
如果(typeof运算数据==字符串){
XML =新的ActiveXObject(Microsoft.XMLDOM);
xml.async = FALSE;
xml.loadXML(数据);
} 其他 {
XML =数据;
}
//对象XML可返回的数据
}
});
这工作对我来说也是如此。
I'm working on a offline version of a website using jQuery and some xml files. I'm running in to a problem in jQuery when I do a $.ajax call on a xml file jQuery throws a error.
When I look at the error I can tell its loading the XML file because its in the error's responceText property. It seams to work just fine in Firefox.
This is how my call looks
$.ajax({
type: "GET",
url: "Modules/" + ModuleID + "/ModuleContent.xml",
dataType: "xml",
success: function(x) { xml = x; ProcessXML(); },
error: function(x) { alert(x.responceText); }
});
When I run this on a web server it works just fine. Its only when I run it from the file its self when I have this problem.
Any ideas on how I can make this work in IE?
Edit: I found the answer to my problem. Here
From the link that the OP posted with the answer:
When loading XML files locally, e.g. a CD-ROM etc., the data received by Internet Explorer is plain-text, not text/xml. In this case, use the dataType parameter to load the xml file as text, and parse the returned data within the succes function
$.ajax({
url: "data.xml",
dataType: ($.browser.msie) ? "text" : "xml",
success: function(data){
var xml;
if (typeof data == "string") {
xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.loadXML(data);
} else {
xml = data;
}
// Returned data available in object "xml"
}
});
This worked for me as well.
这篇关于本地HTML文件AJAX调用和jQuery愁楚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!