使用 Opera 和 Chrome 浏览器管理 XML/Ajax
首先,抱歉我的英语不好,我是卡斯蒂利亚人...
我需要这方面的帮助:我有一个网络,可以从 XML 文件中捕获数据。
我的代码是这样的:
$(function() {
$.ajax({
type: "GET",
cache: false,
dataType: ($.browser.msie) ? "text" : "xml",
success: parseXML,
error: function(){alert("Error: Something went wrong");}
});
});
function parseXML(){
var xml = null;
if (typeof window.ActiveXObject != 'undefined' )
{ // code for IE
xml = new ActiveXObject( "Microsoft.XMLDOM" );
}
else if((typeof document.implementation != 'undefined' ) && (typeof document.implementation.createDocument != 'undefined'))
{ // code for Mozilla, Firefox, Opera, etc.
//xml = new XMLHttpRequest();
xml = document.implementation.createDocument( "", "", null );
}
else{
xml = new XMLHttpRequest();
}
xml.async=false;
xml.resolveExternals = false;
xml.validateOnParse = false;
xml.load("dades.xml");
total=$(xml).find('llibre').size();
$(xml).find('llibre').each(function(){
var desc = $(this).find('descripcio').text()
var img = $(this).find('imatge').text();
var url = $(this).find('url').text();
....
在这里我使用这个变量,但是在 Chrome 和 Opera 浏览器中我在 $.ajax({"Something goneError" 但在 Firefox 和 Internet Explorer 中它是有效的。
非常感谢您的任何答复
first of all, sorry form my poor english, I'm Castilian...
I need help with this: I have a web where I catch data from a XML file.
My code is this:
$(function() {
$.ajax({
type: "GET",
cache: false,
dataType: ($.browser.msie) ? "text" : "xml",
success: parseXML,
error: function(){alert("Error: Something went wrong");}
});
});
function parseXML(){
var xml = null;
if (typeof window.ActiveXObject != 'undefined' )
{ // code for IE
xml = new ActiveXObject( "Microsoft.XMLDOM" );
}
else if((typeof document.implementation != 'undefined' ) && (typeof document.implementation.createDocument != 'undefined'))
{ // code for Mozilla, Firefox, Opera, etc.
//xml = new XMLHttpRequest();
xml = document.implementation.createDocument( "", "", null );
}
else{
xml = new XMLHttpRequest();
}
xml.async=false;
xml.resolveExternals = false;
xml.validateOnParse = false;
xml.load("dades.xml");
total=$(xml).find('llibre').size();
$(xml).find('llibre').each(function(){
var desc = $(this).find('descripcio').text()
var img = $(this).find('imatge').text();
var url = $(this).find('url').text();
....
And here I work with this vars, but in Chrome and Opera browsers I have the error in $.ajax({"Something went wrong"
But in Firefox and Internet Explorer it that works.
A lot of thanks for any answer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AJAX 调用似乎是正确的,并且当我执行它时,我在 Chrome 控制台中没有看到任何错误。您能发布您收到的完整错误吗?我认为错误是在 parseXML 函数中而不是在 AJAX 调用中。
The AJAX call seems right and I see no error in the Chrome Console when I execute it. Could you post the full error you get? I think the error is in the parseXML function and not in the AJAX call.
我的完整 parseXML 函数:
我认为函数的其余部分并不重要,因为我只将 de vars 放在 html 标签中......
My full parseXML function:
I think that the rest of the function doesn't matter because I only put de vars in html tags...