Page Ajax Request Syntax:
$.ajax ({type: "Get", Async:false,cache:false,url: "http://localhost:8081/a/b", data: {produ_id:111,sub_id:0,produ_q Uantity:1,produ_price:0.0},datatype: "Jsonp", Jsonp: "Jsonpcallback", success:function (data) {var d = Data;alert (d);}, Error:function () {alert (' fail ');}});
Java service-side notation:
public void Ajaxrequest (params params) {HttpServletRequest request =; HttpServletResponse response =; Response.setcontenttype ("Text/plain"); Response.setheader ("Pragma", "No-cache"); Response.setheader ("Cache-control", "No-cache"); Response.setdateheader ("Expires", 0); map<string, string> map = new hashmap<string, string> (); Map.put ("Result", "content"); PrintWriter out = null;try {out = Response.getwriter (); String jsonstring = jsonobject.tojsonstring (map);//Use whichever jsonobject you want, just go to JSON-formatted string jsonpcallback = Request.getparameter ("Jsonpcallback");//Client request parameter Out.println (Jsonpcallback + "(" + jsonstring + ")");//return JSONP format data} catch (IOException e) {e.printstacktrace ();} finally{out.flush (); Out.close ();}}
Ajax cross-domain requests, page and Java service-side notation