ajax 跨域请求

来源:互联网 发布:python datetime模块 编辑:程序博客网 时间:2024/06/05 07:11
function ajaxRqquest(){
var url = "http://localhost:8080/XXXX/user/test.htm?callback=?";
$.ajax({
url: url,
data: {username: "uname"},
type: "post",
dataType:'jsonp', //jsonp
cache: false,
success:function(data){
var data = data;
console.log(data+"..................141");   
},
});

}




@RequestMapping(value = "/test") 
@ResponseBody
public String  test(String username,  HttpServletRequest request,
HttpServletResponse response)throws IOException {
   String callback = request.getParameter("callback");
   String json = "{\"username\":\""+username+"\"}";
   response.setContentType("text/html");
   response.setCharacterEncoding("utf-8");
   String result = callback + "(" + json + ")"; //返回的数据较以往的区别是 将返回数据用callback()包裹
   System.out.println(result);   
   return result;
}
0 0
原创粉丝点击