AJAX超時處理

2021-08-31 22:28:41 字數 2149 閱讀 2069

/*!

* 乙個簡單的ajax類

* author: [email protected]

* date: 2010/06/04 friday

** @param function fnbefore 使用者自定義函式 ajax開始前執行,若無則為null

* @param function fnafter 使用者自定義函式 ajax完成後執行,若無則為null

* @param function fntimeout 使用者自定義函式 ajax請求超時後執行,若無則為null

* @param integer itime 設定超時時間 單位毫秒

* @param boolean bsync 是否為同步請求,預設為false

*/function ajax(fnbefore,fnafter,fntimeout,itime,bsync)

ajax.prototype =

*/ formatparam : function( data )

return r.join('&');

}, /**

* 建立 xmlhttprequest物件

*/ create : function() else catch(e) {}

} },

/*** 傳送請求

* * @param string url 請求位址

* @param object or string data 可以是字串或json格式的資料,如:

* @param string method 請求方式 : get or post

* @param boolean ifcache 返回資料是否在瀏覽器端快取,預設為false;

*/ send : function(url,data,method,ifcache)

return true;

},this.time);

var sendbody = this.formatparam(data);

if ( 'get' == method )

if ( ! ifcache )

this._request.open(method,url,this.async);

this._request.onreadystatechange = function()

}} this._request.send( sendbody );

}, /**

* 簡單的get請求

* * @param string url 請求位址

* @param null or string or object data

* @param object html element or string id e

* @param string loading loading時在e中的顯示

* @param boolean ifcache 瀏覽器是否快取

*/ get : function(url,data,e,loading,ifcache)

this.before = function()

}this.after = function(s)

this.timeout = function()

this.send(url,data,"get",ifcache ? true : false);

}};

ajax超時處理重點關注紅色部分,包括jquery、prototype處理都一樣,如下例:

request: function(),5000);

new ajax.request(

this.url,,

on404 : this.on404});

}

如果是呼叫成功,則需要去掉超時,如下:

request: function(),5000);

new ajax.request(

this.url,

}self.callback(t);},

on404 : this.on404});

}

ajax 超時設定

今天在測試工程時發現乙個action執行了2遍 這個操作大致需要5分多鐘才能完成,工程環境 apache2 tomcat6.0。網上搜尋發現了幾個可以設定超時的地方 1.ajax 語法去設定單位毫秒,例如 ajax error function 2.tomcat配置 server.xml 單位毫秒 ...

C 超時處理

在網上搜尋了很多c 超時處理的方法,下面一種是我除錯過的 超時處理 public class timeoutchecker public bool wait long timeout this.dispose return flag private void dispose 呼叫超時處理方法 檢查攝...

php curl 超時處理

php curl處理請求超時 背景 寫了乙個api管理的工具,增加了api請求的的工具,某些介面請求時間比較長,某些介面時間必須要短,希望超過超時時間的請求返回其它的狀態碼,要跟失敗或者curl失敗區分開,本質上雖然都是curl失敗但是從需求角度要區分開,但是php的curl沒有類似事件的一些操作 ...