JQuery ajax () get xml response text

I am trying to extract XML from the Gmail API. I still have this:

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

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

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

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()); } }); 

he says that he "cannot call the replace method from undefined": o

+8
source share
3 answers

data not an xhr object, it is your xml string converted to an XML Document . Therefore, it does not have the responseText property if the xml document does not have a Text node response. Also, add dataType: "xml" to your ajax options if you expect 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 editing) that this is an infact xhr object ... It's weird ...

+10
source

Try data.responseText [0] instead of data.responseText.

EDIT: https://mail.google.com/mail/feed/atom/ He asks me to log in.

+1
source

If you just want to show the answer in text format, you can simply do

 dataType: "text", 

 $.ajax({ url: "https://miranda-zhang.imtqy.com/cloud-computing-schema/v1.0/ontology.xml", dataType: "text", success: function(text) { $('textarea').val(text); }, }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <textarea cols="60" rows="10"></textarea> 
+1
source

All Articles