Jquery ajax request Tool
Method of calling in js:
Var params = {}; params ["aakey"] = "aavalue"; params ["bbkey"] = "bbvalue"; $. cosajax ({url: path + "**. action ", data: params, // an object that contains many key-value pairs. jquery automatically converts callback to the form of aakey = aavalue & bbkey = bbvalue: function (result) {}});
Function checkSessionTimeOut (result) {// adds a session Timeout value to determine if (result &&! (Result. success) & result. message = 'timeout') {top.doc ument. location = path + '/frame. action '; returntrue;} return false;} function showTip (msg, callback) {$ ("# mask_bg" ).css ("z-index", "9999 "); // place the window at the top $ ("# okbtn "). unbind (); // delete other okbtn events $ ("# mask_new "). show (); $ ("# okbtn "). one ('click', callback); // adds a click event to hide tip} function hideTip () {$ ("# mask_new "). hide (); $ ("# mask_bg "). hide ();} jQuery. extend ({ Cosajax: function (opts) {opts = jQuery. extend ({url: "", data: "", isWait: false, isClose: true, callback: function () {returnfalse ;}, fail: function () {returnfalse ;}}, opts ||{}); // the opts following the comma |{} is an extension of the previous $. ajax ({type: "POST", dataType: "json", url: opts. url, async: false, data: opts. data, // use & connect timeout: 180000, beforeSend: function () {}, complete: function (result) {if (! Opts. isWait) {// The complete method hiddenWait () ;}}, success: function (result) {// adds session timeout to determine if (checkSessionTimeOut (result )) {return;} if (result. success) {opts. callback (result); // call the callback method} else {if (opts. isClose) {// close the window closeWindows (); var errTipMessage = result. message; switch (result. message) {case '000000': errTipMessage = "operation failed"; break; default: errTipMessage = result. message; break;} showTip (errTipMessage, hideTip); // hiteTip is the callback function of the Click Event} else {hiddenWait (); opts. fail (result) ;}}, error: function () {if (opts. isClose) {closeWindows (); showTip ("Operation failed", hideTip);} else {hiddenWait (); opts. fail ();}}});}});