Introduction to JQuery + ajax + jsonp cross-origin access, jqueryjsonp
Jsonp (JSON with Padding) is a "usage mode" in json format that allows webpages to obtain information from other domains.
I. Client
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
Ii. 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 ") public void exchangeJson (HttpServletRequest 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 as needed. getParameter ("jsonpCallback"); // The client request parameter out. println (jsonpCallback + "(" + resultJSON. toString () + "); // return the out data in jsonp format. flush (); out. close ();} catch (IOException e) {e. printStackTrace ();}}}
The above is a simple introduction to JQuery + ajax + jsonp cross-origin access. I hope you can provide more support ~