The
development process, AJAX applications should be said very frequently, of course, jquery Ajax functions have been very useful, but small series or slightly sorted, convenient for different needs, you can simplify the input parameters, the following is the instance code:
$ (function () {/** * ajax encapsulation * URL sends the requested address * data sent to the server, array storage, such as: {"date": new Date (). GetTime (), "state": 1} * Async Default value: True. All requests are asynchronous requests under the default settings.
If you need to send a sync request, set this option to false.
* Note that the synchronization request will lock the browser and 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 returned data type, commonly used such as: XML, HTML, JSON, text * SUCCESSFN successful callback function * ERROR FN Failed callback function */jquery.syncajax=function (URL, data, async, type, DataType, SUCCESSFN, errorfn) {async = (Async==nul L | | 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 Package * URL sends the requested address * data sent to the server, array storage, such as: {"date": new Date (). GetTime (), "state": 1} * SUCCESSFN successful callback function */jquery.jsonajax=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 Package * URL sends the requested address * data sent to the server, array storage, such as: {"date": new Date (). GetTime (), "state": 1} * DataType expected server The returned data types, such as XML, HTML, JSON, text * SUCCESSFN successful callback function * ERRORFN Failure callback function * * jquery.jsonajax2=function (URL, data, suc CESSFN, 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);
}
});
};
});
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.