在原型中,我可以用下面的代码显示“加载…”图像:
var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars,
onLoading: showLoad, onComplete: showResponse} );
function showLoad () {
...
}
在jQuery中,我可以将服务器页面加载到一个元素中:
$('#message').load('index.php?pg=ajaxFlashcard');
但是我如何附加一个加载旋转到这个命令,因为我在原型?
如果你正在使用$.ajax(),你可以使用这样的东西:
$.ajax({
url: "destination url",
success: sdialog,
error: edialog,
// shows the loader element before sending.
beforeSend: function() {
$("#imgSpinner1").show();
},
// hides the loader after completion of request, whether successfull or failor.
complete: function() {
$("#imgSpinner1").hide();
},
type: 'POST',
dataType: 'json'
});
虽然设置名为“beforeSend”,但从jQuery 1.5开始,无论请求类型如何,都将调用“beforeSend”。例如,如果输入:'GET', .show()函数将被调用。