Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery ajax() get xml response text

I'm trying to retrieve some XML from the Gmail API. I have this so far:

$.ajax({
    url: "https://mail.google.com/mail/feed/atom/",
    success: function(data) {
        console.log(data.responseText);
    }
});

I know for sure that the array data has a value called responseText because the console tells me so when I get my code to log data. However, when I try to log data.responseText, it logs data and ignores the fact that I specified a parameter (it doesn't say that responseText is not defined). What am I doing wrong?

Edit: here is a screenshot of what the console says data is:

Edit, in response to Kevin: I tried this:

$.ajax({
    url: "https://mail.google.com/mail/feed/atom/",
    dataType: "xml",
    success: function(data) {
        console.log($("feed fullcount",data).html());
    }
});

it says that it "Cannot call method 'replace' of undefined" :o

like image 716
Bluefire Avatar asked Nov 08 '12 22:11

Bluefire


1 Answers

data is not an xhr object, it is your xml string converted into an XML Document. Therefore, it doesn't have a responseText property unless the xml doc has a responseText node. Also, add dataType: "xml" to your ajax options if you are expecting xml.

$.ajax({
    url: "https://mail.google.com/mail/feed/atom/",
    dataType: "xml",
    success: function(data) {
        console.log(data);
    }
});

Edit: Now i see in your question (after edit) that it is infact an xhr object... That's odd...

like image 157
Kevin B Avatar answered Sep 27 '22 18:09

Kevin B