Page Call Code
$.ajax ({
async:false,
type: ' Post ',
dataType: "Jsonp",
URL: "Http://127.0.0.1:8080/query.do?" Action=clients ",
success:function (data) {
alert (data);
},
error:function (XMLHttpRequest, Textstatus, Errorthrown) {
alert ("Status: +xmlhttprequest.status
+", ReadyState: "+ Xmlhttprequest.readystate
+ ", Textstatus:" +textstatus);
}
Set parameters: Async:false,datatype: "Jsonp", can achieve cross-domain access, but the return has been the error function, Serverlet background success, using Firefox browser debugging, found that the URL sent to http://127.0.0.1:8080 /query.do?action=clients&callback=jquery21305029407908107708_1449541331780, found a callback parameter, access to information, Modify return data content can be successfully accessed, modify the background code as follows:
try{result = String.Format ("%s);", Request.getparameter ("callback"), "Hello wrold!");
Servletoutputstream OS = Response.getoutputstream ();
Os.write (Result.getbytes ());
Os.flush ();
Os.close (); The catch (Exception e) {log.error (E.getmessage ());}