First step: Introducing the jquery Library
JQuery Ajax Package General Class (ZZW) ********* /$ (function () {/** * Ajax package * URL Send request address * data send Data 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 = (dat A==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); } }); };
<%@ 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" > $(function() {$.ax (Getrootpath ()+ "/test/ajax.html", NULL, NULL, NULL, NULL, function(data) {alert (data.code); }, function() {alert ("Something went wrong."); } ); $.axs (Getrootpath ()+ "/test/ajax.html",NULL,function(data) {alert (data.data); }); $.axse (Getrootpath ()+ "/test/ajax.html", NULL, function() {alert ("It worked."); }, function() {alert ("Something went wrong."); }); }); </script> <%@ 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" > $(function() {$.ax (Getrootpath ()+ "/test/ajax.html", NULL, NULL, NULL, NULL, function(data) {alert (data.code); }, function() {alert ("Something went wrong."); } ); $.axs (Getrootpath ()+ "/test/ajax.html",NULL,function(data) {alert (data.data); }); $.axse (Getrootpath ()+ "/test/ajax.html", NULL, function() {alert ("It worked."); }, function() {alert ("Something went wrong."); }); }); </script> });
JQuery Ajax Universal JS Package