嘗試使用.find()
從.ajax()
返回的數據中找到div
元素,id="result"
。不幸的是,alert(result)
不返回div#result
。從.ajax()調用的數據上的jQuery .find()返回「[object Object]」而不是div
這裏是我的代碼:
$.ajax({
url: url,
cache: false,
success: function(response) {
result = $(response).find("#result");
alert(response); // works as expected (returns all html)
alert(result); // returns [object Object]
}
});
不響應進來的拳頭地方:'警報(響應)'? – Sarfraz 2010-07-21 14:34:06
我不知道如何修正你的代碼,但是我認爲它會起作用,如果你首先把內容放在一個div標籤中並且顯示none,然後在這個div裏面找到#result標籤。像:$('#div-content')。html(result); $( '#DIV內容')找到( '#結果'); – 2010-07-21 14:35:46