一、jQuery Ajax请求
let ajaxTimeOut = $.ajax({ //将网络请求事件赋值给变量ajaxTimeOut url: "/api_v1.1/apiPackage/knowKeyWord", type: "GET", dataType: "json", data: { "knowcontent": this.state.title + this.state.description, }, timeout: 2000, //通过timeout属性,设置超时时间 success: function (data) { console.log("获取关键字成功"); console.log(data); }.bind(this), error: function (xhr, status, err) { }.bind(this), complete: function (XMLHttpRequest, status) { //当请求完成时调用函数 if (status == 'timeout') {//status == 'timeout'意为超时,status的可能取值:success,notmodified,nocontent,error,timeout,abort,parsererror ajaxTimeOut.abort(); //取消请求 Modal.warning({ //超时提示:网络不稳定 title: '友情提示', content: '网络不稳定', }); } } });
二、jQuery Ajax请求
$.ajax({ url:"https://heidongbuhei.github.io/test/pages/"+pagrUrl, type:"get", data:{}, async:true, dataType:"html", beforeSend:function(){ $(".loading-box").show(); }, complete:function(){ $(".loading-box").hide(); }, success:function (data) { console.log(data); $(".change-part").html(data); }, error:function (data) { console.log(data.status); } })