gpt4 book ai didi

php - 使用 jquery 从 php 解析 XML

转载 作者:行者123 更新时间:2023-11-30 18:37:57 25 4
gpt4 key购买 nike

我在 php 中有一个编写 XML 的脚本。

我使用 ajax 调用来读取该 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);
}
});

在 php 上我有这个:

<?php
header('Content-Type: application/xml; charset=UTF-8');

...
?>

(尝试使用 application/xml 和 text/xml)

问题:

在 Google Chrome 中工作得很好,在 IE9 和 Firefox 上失败,readyState: 4,status: 200 和 Error: parsererror

编辑:一小段示例 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>

最佳答案

您确定您的编辑器设置编码是 utf-8 并且您将这个 xml/php 文件保存为 utf-8 吗?

在 firefox 中使用 firebug 检查生成调用的错误。也许只是您的 xml 中的一些无效的 utf-8 字符。

关于php - 使用 jquery 从 php 解析 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7712219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com