前端
$.jsonp({
url: "http://10.12.8.69:8290/dd_SJ/rest/shuntRest/synchronous",
contentType: "application/x-www-form-urlencoded; charset=utf-8",
data: {
type: Ctype,
mobileNo: MobileNo,
linkMan: LinkMan,
contactNumber: ContactNumber,
problemTypes: ProblemTypes,
province: Province,
city: City,
region: Region,
fullAddress: FullAddress,
concreteProblems: ConcreteProblems
},
jsonp: "callback",
callback: "success_jsonpCallback",
error: function (xOptions, textStatus) {
// 错误发生时,立即执行
console.log('exec ERROR');
},
success: function (res) {
console.log('req success:' + res.success);
if (res.success=="true") {
alert("提交成功");
}
}
});
后端
//JSONP测试服务端
@RequestMapping(value ="/thirdparty/palmhall/orderTransferToHollyV8", produces={"text/html;charset=UTF-8;","application/json;"})
@ResponseBody
public void orderTransferToHollyV8(HttpServletResponse response,HttpServletRequest request, SheetVo vo)throws UnsupportedEncodingException {
JSONObject returnJson =new JSONObject();
//String name = new String(vo.getCity().toString().getBytes("ISO-8859-1"), "GBK");
String city = ParamUtils.getParameter(request, "city");
//city = new String(city.getBytes("ISO-8859-1"),)
String str=new String(vo.getCity().getBytes("ISO-8859-1"),"utf-8");
PrintWriter pw =null;
returnJson.put("success", "true");
try {
pw = response.getWriter();
//success_jsonpCallback与前台保持一致
pw.write("success_jsonpCallback" +"(" + returnJson.toString() +")");
pw.close();
pw =null;
}catch (Exception e) {
log.error(e, e);
returnJson.put("result", "FAIL");
returnJson.put("message", "系统异常,请稍候再试。");
}
}