tags:

views:

44

answers:

1

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?

A: 

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();
    }
});
Ken Browning
Thanks, Does that work when the url is on a different domain?
vikasde
I get a 403 when using the xml datatype.
vikasde