當前位置:首頁 » 電腦故障 » ajax獲取網路異常

ajax獲取網路異常

發布時間: 2022-08-17 17:15:44

㈠ ajax,在action如何獲取到 http_request.responseText的值

沒看明白LZ 的意思

㈡ ajax同步非同步異常處理區別

同步:httpRequest.open('POST', url, false);

非同步:httpRequest.open('POST', url, true);

二者區別:http://www.cppblog.com/converse/archive/2009/05/13/82879.html

㈢ 打開網站時出現:ajax操作發生異常

你如果用jquery、prototype等框架寫的ajax,檢查你的請求方式有沒有問題 希望對你有所幫助!

㈣ 如何檢測ajax因網路斷開或延時導致的錯誤並重連

$.ajax({
async:true,//true非同步,false同步
url:'',
data:$(this).serialize(),
type:'get',
dataType:'json',//xml,html,script,json,jsonp,text
complete:function(XHR,TS){alert('complete');},//完成回調函數(XHR,TS)
error:function(XMLHttpRequest,textStatus,errorThrown){
//XMLHttpRequest.readyState:
//0-(未初始化)還沒有調用send()方法
//1-(載入)已調用send()方法,正在發送請求
//2-(載入完成)send()方法執行完成,已經接收到全部響應內容
//3-(交互)正在解析響應內容
//4-(完成)響應內容解析完成,可以在客戶端調用了
//XMLHttpRequest.status:
//textStatus:"timeout","error","notmodified"和"parsererror"。
//(0)null
//(1)timeout超時
//(2)error
//(3)notmodified未修改
//(4)parsererror解析錯誤
console.log(XMLHttpRequest);
console.log(textStatus);
console.log(errorThrown);

},//默認值:自動判斷(xml或html)。請求失敗時調用此函數。有以下三個參數:XMLHttpRequest對象、錯誤信息、(可選)捕獲的異常對象。
success:function(response){alert('success');}
});

可以通過error的狀態來判斷請求狀態,來做異常處理。

㈤ c# 模擬提交Ajax請求。返回系統繁忙

1、網路異常慢的時候
2、Ajax是非同步傳輸,你返回系統忙看一下是不是其它地方寫錯了
3、建議你可以alert(data);

㈥ jquery或者js如何判斷當前網路是否暢通,我的頁面是給手機用的

代碼邏輯如下:

jQuery.ajax({
url:"",
dataType:"",
type:"",
success:function(data){
//...調用成功代碼
},
error:function(XMLHttpRequest,textStatus,errorThrown){
alert(XMLHttpRequest.status);//查看請求狀態
//調用失敗代碼
}
});

通過ajax的error參數判斷當前網路狀況。

㈦ 社保網ajax請求異常怎麼處理

第一步:controller中@RequestMapping("/ajaxerror")public String ajaxerror() {

return "thymeleaf/ajaxerror";}

//一個異常包下的類,一個html,一個js
@RequestMapping("/getAjaxerror")
@ResponseBody
public IMoocJSONResult getAjaxerror() {
int a = 1 / 0;
return IMoocJSONResult.ok();
}

第二步:html中

<!DOCTYPE html >

<html>
<head>
<meta charset="UTF-8" />
<title></title>
<script th:src="@{/static/js/jquery.min.js}"></script>
</head>
<body>

<h1>測試ajax錯誤異常</h1>

<script th:src="@{/static/js/ajaxerror.js}"></script>

</body>
</html>

標准ajax請求

$.ajax({
url: "/err/getAjaxerror",
type: "POST",
async: false,
success: function(data) {
debugger;
if(data.status == 200 && data.msg == "OK") {
alert("success");
} else {
alert("發生異常:" + data.msg);
}
},
error: function (response, ajaxOptions, thrownError) {
debugger;
alert("error");
}
});

第三步異常類在exception包中IMoocExceptionHandler

詳情參考代碼

第四步前端請求http://localhost:8080/err/ajaxerror

結果報異常 alert一下

因js是先執行,所以執行完後就會顯示前端文字信息