java 后台程序:
@Controller
public class TaskDetailController {
@ResponseBody
@RequestMapping(value = "/test.json", produces = "text/html;charset=UTF-8")
public String getTaskDetailByTaskId(String testId, HttpServletRequest request){
String callback = request.getParameter("callback");
if(null != callback){
String resultJsonp = callback + "(" + jsonObject.toString() + ")";
return resultJsonp;
}else{
return jsonObject.toString();
}
}
}
前端程序调用代码:
ur3 = "http://ip:8080/balantflow/module/sf/test.json"
$.ajax({
type: "get",
//async: false,
url:ur3,
data: "testId=123",
dataType:"jsonp",
jsonp:"callback",
success:function(json){
alert(json);
},
error: function(){
alert('fail');
}
});