JQuery Ajax Encapsulation Generic class

Source: Internet
Author: User

/*****************************************************************
jQuery Ajax Package (Universal)
*****************************************************************/
$ (function () {
/**
* Ajax Encapsulation
* URL to send the requested address
* Data sent to the server, array storage, such as: {"date": new Date (). GetTime (), "state": 1}
* Async Default value: True. By default, all requests are asynchronous requests. If you need to send a synchronization request, set this option to false.
* Note that the sync request will lock the browser, and the user's other actions must wait for the request to complete before it can be executed.
* Type Request method ("POST" or "get"), default to "get"
* DataType expected server to return the data type, commonly used such as: XML, HTML, JSON, text
* SUCCESSFN Successful callback function
* ERRORFN Failure callback function
*/
Jquery.ax=function (URL, data, async, type, DataType, SUCCESSFN, ERRORFN) {
Async = (Async==null | | async== "" | | typeof (ASYNC) = = "undefined")? "True": async;
Type = (Type==null | | type== "" | | typeof (type) = = "undefined")? "POST": type;
DataType = (Datatype==null | | datatype== "" | | typeof (DATATYPE) = = "undefined")? "JSON": dataType;
data = (Data==null | | data== "" | | typeof (DATA) = = "undefined")? {"Date": new Date (). GetTime ()}: data;
$.ajax ({
Type:type,
Async:async,
Data:data,
Url:url,
Datatype:datatype,
Success:function (d) {
SUCCESSFN (d);
},
Error:function (e) {
ERRORFN (e);
}
});
};
/**
* Ajax Encapsulation
* URL to send the requested address
* Data sent to the server, array storage, such as: {"date": new Date (). GetTime (), "state": 1}
* SUCCESSFN Successful callback function
*/
Jquery.axs=function (URL, data, SUCCESSFN) {
data = (Data==null | | data== "" | | typeof (DATA) = = "undefined")? {"Date": new Date (). GetTime ()}: data;
$.ajax ({
Type: "Post",
Data:data,
Url:url,
DataType: "JSON",
Success:function (d) {
SUCCESSFN (d);
}
});
};

/**
* Ajax Encapsulation
* URL to send the requested address
* Data sent to the server, array storage, such as: {"date": new Date (). GetTime (), "state": 1}
* DataType expected server to return the data type, commonly used such as: XML, HTML, JSON, text
* SUCCESSFN Successful callback function
* ERRORFN Failure callback function
*/
Jquery.axse=function (URL, data, SUCCESSFN, ERRORFN) {
data = (Data==null | | data== "" | | typeof (DATA) = = "undefined")? {"Date": new Date (). GetTime ()}: data;
$.ajax ({
Type: "Post",
Data:data,
Url:url,
DataType: "JSON",
Success:function (d) {
SUCCESSFN (d);
},
Error:function (e) {
ERRORFN (e);
}
});
};

});

JQuery Ajax Encapsulation Generic class

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.