This article is divided into three steps to achieve jquery Ajax through the JS package, through the code example to explain the code with annotations, more easily understood, the details are as follows:
The first step: the introduction of the jquery Library
The second step: the development of Ajax encapsulation class, has been tested through, can be directly invoked, directly affixed to the code, the explanation on the province
/***************************************************************** JQuery Ajax Package Universal Class (LINJQ) ********************** /$ (function () {/** * ajax encapsulation * URL sends the requested address * data sent to the server, array storage, such as: {"date": NE W 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 * 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 Package * 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 Package * URL sends the requested address * data sent to the server, array storage, such as: {"date": new Date (). GetTime (), "state": 1} * DataType expected server return data type, commonly used as : XML, HTML, JSON, text * SUCCESSFN successful callback function * ERRORFN Failure callback function * * jquery.axse=function (URL, data, SUCCESSFN, ERRORFN) {data = (d Ata==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);
}
});
}; });
Step three: Invoke Impersonation
<%@ page language= "java" pageencoding= "Utf-8"%> <% String Path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" + request.getservername () + ":" + request.getserverport () + path + "/"; %> <!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
The above is a small set to introduce the jquery Ajax General JS Packaging related knowledge, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!