ajax跨域获取返回值
js代码
$.ajax({ async:false, url: 'https://***/api/prepareApi.getDanMu?sqlMapId=findBarrage', // 跨域URL type: 'get', dataType: 'jsonp', jsonp: 'jsoncallback', //默认callback jsonpCallback: 'handleResponse', //设置回调函数名 //data: mydata, timeout: 5000, success: function(data){ } }});
后台代码 (返回时 转json格式,括在js自定义回掉函数名里)
@RequestMapping("api/prepareApi.getDanMu") public String getDanMu() throws Exception { Map<String, Object> map = getParameterMap(); System.out.println("api/prepareApi.getUserUploadWeiKeTeachApi: " + map); map.put("sqlMapId", map.get("sqlMapId").toString()); List<Map<String, Object>> list = openDap.queryForList(map); return "handleResponse(" + JSONArray.parseArray(JSON.toJSONString(list)) + ")"; }