JSONP (JSON with Padding) is a "usage pattern" of data format JSON that enables Web pages to retrieve data from other domains.
A. Client
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
two. Server Side
Import java.io.IOException;
Import Java.io.PrintWriter;
Import Java.util.HashMap;
Import Java.util.Map;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
Import Net.sf.json.JSONObject;
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping; @Controller public class Exchangejsoncontroller {@RequestMapping ("/base/json.do") is public void Exchangejson (Httpser
Vletrequest request,httpservletresponse response) {try {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 = Response.getwriter (); Jsonobject Resultjson = jsonobject.fromobject (map); Assemble json String Jsonpcallback = request.getparameter On Demand("Jsonpcallback");//Client request Parameters Out.println (jsonpcallback+ "+resultjson.tostring (1,1) +"));//return JSONP format Data Out.flush (
);
Out.close ();
catch (IOException e) {e.printstacktrace ();
}
}
}
The above is a small series for everyone to talk about Jquery+ajax+jsonp across the domain access to all the content, I hope that we support cloud-Habitat Community ~