我有以下XML,它在發出AJAX請求後返回給我。使用jQuery從XML文檔中檢索值
<entry xml:base="url" xmlns="http://www.w3.org/2005/Atom"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<id>URL</id>
<category term="SomeCategory" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"></category>
<link rel="edit" title="Table" href="Table(56)">
<link rel="SomeURL" type="application/atom+xml;type=entry" title="table" href="table(56)/table1">
<link rel="SomeURL" type="application/atom+xml;type=entry" title="table" href="table(56)/table2">
<link rel="SomeURL" type="application/atom+xml;type=feed" title="table" href="table(56)/table3">
<link rel="SomeURL" type="application/atom+xml;type=entry" title="table" href="table(56)/table4">
<title></title>
<updated>2016-01-16T02:35:51Z</updated>
<author>
<name></name>
</author>
<content type="application/xml">
<m:properties>
<d:NewlyCreatedId m:type="Edm.Int32">56</d:NewlyCreatedId>
</m:properties>
</content>
我試圖獲得價值56
出它使用jQuery的,這是我的AJAX方法在我的成功方法:
success: function (data) {
var selectedId = data.find('d:NewlyCreatedId').val();
alert(selectedId);
}
但是,這會產生錯誤:
Uncaught TypeError: data.find is not a function
有人可以建議我如何去拉這個XML文檔的價值請。
*更新*
我已經試過了在答案的建議,但是這是現在返回空在那裏我提醒selectedId。
裏面我的成功方法,我現在有這樣的:
var selectedId = $(data).find('d\\:NewlyCreatedId').text();
更新的問題與完整的XML文檔
*更新*
我一直在爭奪這一切的一天,我將我的ajax方法中的數據類型更改爲xml
,嘗試循環但無濟於事。有人可以對此有所瞭解嗎?
謝謝你提供的代碼片段,當我嘗試你的代碼,並警告selectedId它似乎空,甚至我認爲我可以在瀏覽器中查看響應,並且它有一個有效的數字 –