我試圖在DOM中的元素準備就緒後獲取數據。我試圖從JQUERY中使用load函數,但是我得到一個消息.load()不是函數。在頁面加載時獲取數據
在頁面加載過程中使用ajax獲取元素數據(在我的情況下是div)是否有最佳做法?我使用ASP.NET並在後面的代碼中調用webmethod。
這裏是我的AJAX/jQuery代碼:
$(document).ready(function() {
$(function() {
$("[id$=divArea]").load()(function() {
$.ajax({
type: "POST",
url: "apage.aspx/Role",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (response) {
alert("got data from Role");
},
error: function (data) {
alert("failed to get data from Role");
}
});
});
});
感謝。
.load僅適用於實際加載某些內容的元素,例如iframe圖像和窗口。你究竟在做什麼? –
是否可以在匹配多個元素的jQuery $對象上使用'$ object.load()'? – Blazemonger