开发者

How to process xml returned from jsonp using jquery?

I use the following jquery to return an xml that resides on the same subdomain:

$.getJSON(myurl, function(data) 
{ 
  debugger; 
  alert(data); 
});

Now whenever I run this in firebug, I get a js error in firebug saying: Missing ; before statement. The data returned looks like this:

<开发者_运维问答?xml version="1.0" encoding="utf-8"?>
<string xmlns="somenamespace">...somedata...</string>

The data I want is returned, but I am not sure how to use it. I need to access somedata, however I am not able to. Firebug doesnt even stop in the function. How do I proceed properly?


It appears as if you're expecting XML to be returned but you're calling the function which expects JSON. XML and JSON are two different ways of encoding data.

If you want to get the XML as a string then you can use jQuery's get function. This would require that you parse the string yourself in order to extract ...somedata....

But if you would like to process the content of the XML response with jQuery then your best bet is to use the ajax function:

$.ajax({
    url: myurl,
    dataType: 'xml',
    success: function(data) {
        debugger;
        alert(data);
        // untested:
        var theValue = $('string', data).text();
    }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜