前端js
$.ajax({
url:"url",
type:"post",
dataType:"jsonp",
jsonp:"jsoncallback",
jsonpCallback:"successCallback",
success:function(data){
alert("成功")
},
error:function(){
alert("失败")
}
})
后台代码jsonCallBack里面的函数名称一样
@Controller public class FromData { @RequestMapping("/data.do") public void getData1(HttpServletRequest req,HttpServletResponse rps){ System.out.println("1111111"); String str = "Hello world"; JSONObject json = new JSONObject(); json.put("name", str); try { rps.getWriter().print("successCallback("+json.toJSONString()+")"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }