问题描述
我在PHP中写入XML脚本。
我用Ajax调用来读取XML。
$。阿贾克斯({
网址:http://blablabla.com/myscript.php
数据:requestVars,
数据类型:XML,
成功:函数(XML){
XMLParser的(XML);
},
错误:函数(XHR,ERR){
警报(readyState的:+ xhr.readyState +\ n状态:+ xhr.status +\ n错误:+ ERR);
警报(responseText的:+ xhr.responseText);
}
});
在PHP中我有这样的:
< PHP
标题(内容类型:应用程序/ XML的,字符集= UTF-8);
...
?>
(尝试都与应用程序/ xml和文本/ XML)
问题:
工程就像在谷歌浏览器的魅力,失败的IE9和Firefox当readyState:4,状态:200错误:parsererror
编辑:一小片样品的XML:
< XML版本=1.0编码=UTF-8&GT?;
&所述;指数名称=asdsadisImg =0>
<类别>
<猫n =13>
<标题>影LT; /标题>
< /目录>
<猫n =15>
<标题>图书< /标题>
< /目录>
< /分类>
&所述;主题ID为141打开=0>
<标题>除A< /标题>
<资源ID =553级=2>
<标题>资源A1中/标题>
< /资源>
< /主题>
< /索引>
您确定您的编辑器设置连接code是UTF-8,保存这个XML / PHP文件为UTF-8?
使用萤火虫到Firefox检查什么错误生成你的电话。也许是你的XML里面只是一些不合法的UTF-8字符。
I have a script in php that writes XML.
I use an ajax call to read that XML.
$.ajax({
url: "http://blablabla.com/myscript.php",
data: requestVars,
dataType: 'xml',
success: function(xml){
XMLParser(xml);
},
error: function(xhr,err){
alert("readyState: "+ xhr.readyState + "\nstatus: " + xhr.status + "\nerror:" + err);
alert("responseText: " + xhr.responseText);
}
});
On php I have this:
<?php
header('Content-Type: application/xml; charset=UTF-8');
...
?>
(tried both with application/xml and text/xml)
Problem:
Works like a charm in Google Chrome, fails on IE9 and Firefox with readyState: 4, status: 200 and Error: parsererror
EDIT:A little piece of sample XML:
<?xml version='1.0' encoding='utf-8'?>
<Index Title="asdsad" isImg="0">
<Categories>
<Cat Id="13">
<Title>Movies</Title>
</Cat>
<Cat Id="15">
<Title>Books</Title>
</Cat>
</Categories>
<Subject Id="141" Open="0">
<Title>Subject A</Title>
<Resource Id="553" Level="2">
<Title>Resource A1</Title>
</Resource>
</Subject>
</Index>
Are you sure that your editor setup encode is utf-8 and you save this xml/php file as utf-8?
Use firebug into firefox to check what error is generating your call. Maybe is just some not valid utf-8 character inside your xml.
这篇关于使用jquery从PHP解析XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!