Go directlyCodeAll the introduction is in the code comment.
First, use flyjsonp to implement cross-origin asynchronous requests.
<% @ Page Language = "Java" pageencoding = "UTF-8" %> <SCRIPT type = "text/JavaScript" src = "JS/flyjsonp. min. JS "> </SCRIPT> <SCRIPT type =" text/JavaScript "> function getjfbcustomstate () {flyjsonp. init ({Debug: true}); // initialize the instance of flyjsonp. The debug parameter can be set to true or falseflyjsonp. post ({URL: 'http: // 123. 125. **. * **: 8088/ecpaycus/web/getcustomizebyphoneno ', parameters: {phoneno: '000000'}, success: function (data) {var customstate = data. customstate; alert ('server return result: '+ customstate);}/* success: function (data) {var customstate = data. customstate; alert ('server return result: '+ customstate) ;}, error: function (errormsg) {alert ('22'); console. log (errormsg);} */});} </SCRIPT> <span style = "color: Blue; text-Decoration: underline; cursor: pointer; "onclick =" getjfbcustomstate (); "> click here to complete the customization </span> <% -- ============================ ========================================================== ==================================== flyjsonp homepage: flyjsonp does not rely on any JavaScript framework. You only need to set some parameters to use it to implement cross-origin post and GET requests. In this example, ie9.0.811385421 and firefox9.0.1 passed the test, I found it on this website --> http://site518.net/javascript-cross-domain-request/ :: is the client code, and the following is the service code string phoneno = request. getparameter ("phoneno"); // todo... response. setcontenttype ("application/JSON; charset = UTF-8"); response. getwriter (). print ("{customstate: 'hascustomed'}"); Note: when the server outputs data to the client, the output must be a JSON string, otherwise, the client cannot receive ========================================================== ===================-- %>
The next step is to use jquery to implement cross-origin asynchronous requests.
<% @ Page Language = "Java" pageencoding = "UTF-8" %> <SCRIPT type = "text/JavaScript" src = "JS/jquery-1.7.1.min.js"> </SCRIPT> <SCRIPT type = "text/JavaScript" >$ (function () {$ ('# validatecustom '). click (function () {$. getjson ('HTTP: // 123. 125. **. * **: 8088/ecpaycus/web/getcustomizebyphoneno? Jsoncallback =? & Phoneno = 18601148104 ', function (JSON) {var customstate = JSON. customstate; alert ('server return result: '+ customstate) ;}) ;}</SCRIPT> <span style = "color: blue; text-Decoration: underline; cursor: pointer; "id =" validatecustom "> click here to complete customization </span> <% -- ================ ========================================================== ================================ note: in this example, ie9.0.811116421 and firefox9.0.1 are both tested and used: the client code is above, and the following is the server code string phoneno = request. getparameter ("phoneno"); // todo... string jsoncallback = request. getparameter ("jsoncallback"); string jsonreturn = "{customstate: 'hasmizmized'}"; response. setcontenttype ("application/JSON; charset = UTF-8"); response. getwriter (). print (jsoncallback + "(" + jsonreturn + ")"); Note: when the server outputs data to the client, the output must be a JSON string; otherwise, the client cannot receive and, when the client requests, when the callback function name must be provided and put in the form of parameters after the request URL and output by the server to the client, you must put the received callback function name in front of the JSON string ======================== ========================================================== =========================================-- %>