在使用ajax請求的時候 ,如果服務器返回的是500錯誤,或者其他非正常的http錯誤狀態碼時
會提示下面的錯誤
而我們需要把錯誤信息處理出來
$.ajax({ type:'get', url:"/admin/dologin", async:true, data:data, success:function (res) { console.log(res); layer.msg(res.msg,{time:1000},function () { if(res.status == 0){ var index = parent.layer.getFrameIndex(window.name); //先得到當前iframe層的索引 parent.layer.close(index); //再執行關閉 parent.location.reload(); } }); }, error:function (e) {
//返回500錯誤 或者其他 http狀態碼錯誤時 需要在error 回調函數中處理了 並且返回的數據還不能直接alert,需要使用
//$.parseJSON 進行轉譯 res.msg 是自己組裝的錯誤信息通用變量 var res = $.parseJSON(e.responseText); layer.msg(res.msg); } });