<div id="LoadingImage" style="display: none">
<img src.... />
</div>
function ajaxCall()
{
$("#LoadingImage").show();
$.ajax({
type: "GET",
url: surl,
dataType: "jsonp",
cache : false,
jsonp : "onJSONPLoad",
jsonpCallback: "newarticlescallback",
crossDomain: "true",
success: function(response) {
$.("#LoadingImage").hide();
alert("Success");
},
error: function (xhr, status) {
$.("#LoadingImage").hide();
alert('Unknown error ' + status);
}
});
}
Reference 1 here.
注意,你必須包含JQuery的。
另一個好方法:
$('#loadingDiv')
.hide() // hide it initially
.ajaxStart(function() {
$(this).show();
})
.ajaxStop(function() {
$(this).hide();
})
;
Reference 2 here.
首先-ajax與它無關,你可能是想說'jQuery'。其次,你是否在你的代碼中包含了jQuery插件?您也可以使用chrome - 單擊F12並檢查控制檯選項卡是否有錯誤。 – alfasin
取決於......你究竟在裝什麼?你正在加載數據(圖片,文件等)還是做javasript處理? – Cristy
@alfasin,我包含jquery庫,是否有圖像加載插件? – user1471980