前端js代码:
$.ajax({
url: "http://176.1.19.64:8081/engine/config/" + treeNode.id + ".do?callback=?",
type: "get",
dataType: "jsonp",
scriptCharset: "UTF-8",
jsonpCallback:"successCallback",
data: null,
async: false,
timeout: $.config.ajax.timeout,
success: function (json) {
var reportConfig = JSON.parse(json.reportConfig);
console.log(reportConfig);
$.databrowser.addTab(reportConfig);
}
});
服务端代码:
@RequestMapping(value = WebUrls.URL_CONFIG)
public
@ResponseBody
String getReportConfig(@PathVariable String nodeId, HttpServletRequest request, HttpServletResponse response) {
DynamicRequestParams params = new DynamicRequestParams(request);
String result = "";
try {
result = JsonUtil.objectToJsonStr(engineService.getReportConfig(nodeId));
} catch (MapperException e) {
logger.info(e.getMessage());
e.printStackTrace();
}
try {
String callback = params.get("callback").toString();
JSONObject jsonObject = new JSONObject();
jsonObject.put("reportConfig",result);
result = callback + "(" + jsonObject.toString() + ")";
} catch (Exception e) {
logger.info(e.getMessage());
e.printStackTrace();
}
logger.info("success");
try {
result = new String (result.getBytes("utf-8"),"utf-8");
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage(),e);
e.printStackTrace();
}
logger.info(result);
try {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage(),e);
e.printStackTrace();
}
//response.setContentType("text/plain;charset=ISO-8859-1");
return result;
}
chrome调试显示的网络信息:
General
Request URL:http://176.1.1.167:8080/engine/config/30000102.do? callback=successCallback&_=1489735733373
Request Method:GET
Status Code:200
Remote Address:176.1.1.167:8080
Response Headers
view source
Content-Length:58893
Content-Type:text/plain;charset=ISO-8859-1
Date:Fri, 17 Mar 2017 07:29:00 GMT
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:zh-CN,zh;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Host:176.1.1.167:8080
Pragma:no-cache
Referer:http://176.1.19.64:8081/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Query String Parameters
view source
view URL encoded
callback:successCallback
_:1489735733373
返回的数据片段:
successCallback({"reportConfig":"{\"columnMaxNum\":3,\"id\":\"30000102\",\"rowMaxNum\":3,\"showBlock\":false,\"title\":\"????????\",
现在就是这个问号,不知道怎么处理。查了好多方法,不成功。