开发者

Parsing XML from php using jquery

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 wit开发者_JAVA百科h 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.


It might be that jQuery is unable to parse the XML, but your XMLParser might be.

If that is the case, you can process any result you get with the complete function. It will be called whether or not there is an error (network error or parsing error).

See http://api.jquery.com/jQuery.ajax/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜