Jquery ajax request Tool

Source: Internet
Author: User

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 ();}}});}});

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.