First step: Introducing the jquery Library
<script type= "Text/javascript" src= "<%=path%>/resources/js/jquery.min.js" ></script>
The second step: the development of the Ajax packaging class , has been tested, can be directly called, Direct code, the explanation will save
/***************************************************************** JQuery Ajax Package General Class (LINJQ) ****** /$ (function () {/** * Ajax package * URL to send the requested address * data Data sent to the server, array storage, such as: {"date": new Date (). GetTime (), "state": 1} * Async default: 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 return data type, commonly used such as: XML, HTML, JSON, text * SUCCESSFN successful callback function * ER RORFN Failure callback function */jquery.ax=function (URL, data, async, type, DataType, SUCCESSFN, errorfn) {async = (async==n ull | | 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 Success Callback function */jquery.axs=function (URL, data, SUCCESSFN) {data = (Data==null | | data== "" | | typeof (DATA) = = "Undef Ined ")? {"Date": new Date (). GetTime ()}: data; $.ajax ({type: "Post", Data:data, Url:url, DataType: "JSON", SUCC Ess:function (d) {SUCCESSFN (d); } }); }; /** * Ajax Package * URL to send the requested address * data sent to the server, array storage, such as: {"date": new Date (). GetTime (), "state": 1} * dataType pre- Type of data returned by the server, such as XML, HTML, JSON, text * SUCCESSFN Success Callback function * ERRORFN failed 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", SUCC Ess:function (d) {SUCCESSFN (d); }, Error:function (e) {ERRORFN (e); } }); };});
Step three: Call the simulation
<%@ 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" >JQuery Ajax Universal JS Package