HTML
<div id="loading">
<img src='/jquery/images/loading.gif' />
</div>
< input type="button" id="btn" value="请求">
JS
$('#btn').click(function(){
$.ajax({
url ---- ,根据你需要设置url路径
type:'post',
data:'name=Test',
timeout:15000,
beforeSend:function(XMLHttpRequest){
$("#loading").show();
},
success:function(data,textStatus){
$("#loading").hide();
},
complete:function(XMLHttpRequest,textStatus){
$("#loading").hide();
},
error:function(XMLHttpRequest,textStatus,errorThrown){
$("#loading").hide();
if(status == 'timeout') {
xhr.abort();
$.alert("网络超时,请刷新", function () {
location.reload();
})
}
}
});
});