Jquery ajax跨域访问的问题

2017-04-10 19:15
$(document).ready(function(){

  var orderId="200902001";
  var userId="290001";
 
  var url ='http://dataservice.yimei.com/servlet/addChannelActivityDetail?orderId='+orderId+'&userId='+userId+'&callback=?';


  $.getJSON(url,function(data){});

});

//注意

1) 用$.getJSON这种方式;

2) &callback=?这句很重要

//跨域
String callback = request.getParameter("callback");
.....
JSONArray jsonArray = JSONArray.fromObject(list);
JSONObject json= new JSONObject();
json.put("users", jsonArray);

response.getWriter().write(callback+"("+json.toString()+");");