使用jquery发送ajax的时候,有一个事件比较实用,但往往会被我们忽视,那就是beforeSend。
beforeSend的意思是发送之前的处理,往往用来处理发送之前的动画,避免由于发送时间过长而给用户造成假死的现象。以下图片来自网上:
$.ajax({
url:url,
type:'get',
dataType: "json",
beforeSend: function ()
{
$("body").append('<div
id="pload" style="position:fixed;top:30%;z-index:1200;background:url(/wap/images/loading.gif) top center no-repeat;width:100%;height:140px;margin:auto auto;"></div>');
},
complete: function ()
{
$("#pload").remove();
},
success:function(result){
});