Pages to solve cross-domain problems

1. Background

// warning value
@CrossOrigin
@ RequestMapping ( "/ selectT")
// callback String value with the value jsonp page requires a corresponding
void selectT (HttpServletResponse the Response, String callback) throws IOException {
// set the Chinese front-end coding to ensure receipt of not? ? ? Question mark
the response.setContentType ( "text / HTML; charset = UTF-. 8");
// response.setHeader ( "Access-Control-the Allow-Origin", "JSONP");
thresholdService new new thresholdServiceImp-Service = ();
threshold = threshold threshold new new ();
threshold service.selectThers = (. 1);
the jSONObject jsonObject the jSONObject new new = ();
jsonObject.put ( "threshold", threshold);
// splicing
. response.getWriter () print (callback + "(" + jsonObject .toString () + ")");

}

2, page Ajax wording

.ajax $ ({
of the type: "GET",
url: "HTTP: // IP (server ip address) / threshold / selectT",
<- - get json data!>
dataType: "JSONP",
JSONP: "callback ",
the processData: to false,
Success: function (data) {
console.info (data);
$ (" # fazhi ") HTML (data.threshold.state);.
},
error: function () {
Alert (" loading exception! ");
}
});

Guess you like

Origin www.cnblogs.com/itxiaoxia/p/11446804.html