$.ajax("...", { success: function(data) { /* Do something with data */ }});
是否有可能與CSS選擇器一樣$("body")
數據工作嗎?只獲取數據的body html標籤的內容?
$.ajax("...", { success: function(data) { /* Do something with data */ }});
是否有可能與CSS選擇器一樣$("body")
數據工作嗎?只獲取數據的body html標籤的內容?
如果我理解了您試圖從響應數據中獲取正文的問題。
$(data).find("body");
例子來說明數據的內容 - 身體
$.ajax("...", {
success: function(data) {
/* Do something with data */
alert($(data).find("body").html());
}
});
你沒有嘗試過。 –
我沒有內容的數據來嘗試它,但它應該工作:) –
不,請閱讀我的答案或[文檔](http://api.jquery.com/jQuery/#jQuery2):一些元素是在執行'$(htmlpage)'時過濾掉。 '$(data)'已經是主體內容。 –
如果你想要的是在一個div加載接收數據的片段,您可以使用此:
$('#result').load('test.html body');
見負載功能的參考:http://api.jquery.com/load/
如果你的目標是更如果你想獲得另一部分比身體
$.ajax("...", { success: function(data) {
var $body = $(data); // yes, other elements are filtered out
var bodyHtml = $body.html();
...
}});
,你可以使用一個選擇:一般情況下,你需要的身體,你可以做到這一點
$.ajax("...", { success: function(data) {
var $element = $(data).find('#myId'); // here finds the element with id myId
...
}});
您可以在AJAX方法使用此代碼:
success:function(data){
$("#result").text(data.d);
}
你想與數據到底該怎麼做? – Dev