Front Desk (1) JS The Ajax method that made the request
1 $.ajax ({2URL: "*.do",//url is the path to be requested3Type: "Get",//type is the type of the HTTP request and the value is "get" or "POST"4Data: "key=" + value+ "&key=" + value+ "&key=" +value,/* data is submitted at the time of request, can be obtained by Request.getparameter () in the background
, this can be a URL to the way, you can also put a JavaScript object such as {Key:value,key:value,...} * /5DataType: "JSON",//here if the background is a JSON string, and the foreground wants to use the JSON string as a JavaScript object, the datatype here must be "JSON", otherwise JS will be treated as a normal string6Successfunction(data) {//Here is the callback method executed when the request succeeds, not the callback executed when the operation of the background method succeeds7 processing data returned from the background8 },9Errorfunction(XMLHttpRequest, Textstatus, Errorthrown) {//This is the callback that is executed when the request fails Ten alert (XMLHttpRequest); One alert (textstatus); A alert (errorthrown); - } -});
(2) Usually if you just want to know whether the background execution is successful or not, you do not need to use the JSON string, only need to use Response.getwriter (). Print () outputs a character that represents the result of the execution; However, sometimes you want to pass the background data such as a list containing JavaBean to the foreground, you can use the JSON string; The main method in the background controller method when using JSON string
1 // object is any Java object, such as Java bean,persistent Entity,pojo 2 sonobject jsonobject = Jsonobject.fromobject (object); 3 String jsonstr=jsonobject. toString (); 4 response.getwriter (). print (JSONSTR); 5 return null;
(3) Jar packages that are dependent on retrieving JSON strings in the background
Data processing in the AJAX request of jquery