簡體   English   中英

JQuery ajax()獲取xml響應文本

[英]JQuery ajax() get xml response text

我正在嘗試從Gmail API中檢索一些XML。 到目前為止我有這個:

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

我確信數組數據有一個名為responseText的值,因為當我得到我的代碼來記錄數據時,控制台告訴我。 但是,當我嘗試記錄data.responseText ,它會記錄數據並忽略我指定參數的事實(它沒有說明沒有定義responseText)。 我究竟做錯了什么?

編輯:這是控制台說data的屏幕截圖:

編輯,回應凱文:我試過這個:

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

它說它“無法調用方法'替換'未定義':o

data不是xhr對象,而是將xml字符串轉換為XML Document 因此,除非xml doc具有responseText節點,否則它沒有responseText屬性。 另外,如果您期望xml,請將dataType: "xml"添加到您的ajax選項中。

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

編輯:現在我在你的問題中看到(編輯后)它實際上是一個xhr對象...這很奇怪......

嘗試使用data.responseText [0]而不是data.responseText。

編輯: https//mail.google.com/mail/feed/atom/它要求我登錄。

如果您只想顯示文本格式響應,則可以執行此操作

dataType: "text",

 $.ajax({ url: "https://miranda-zhang.github.io/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> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM