1,第一种方式,Spring通过注解的方式允许跨域
2,第二种方式,JS部分:
var url=" http://192.168.1.58:8080/goods/geGoodsPJson.action " ;
$(function(){
var data = { "location":"2" , "companyId":" " };
$.ajax({
url:url,
data:data,
$(function(){
var data = { "location":"2" , "companyId":" " };
$.ajax({
url:url,
data:data,
dataType:'jsonp',
jsonp:'callback',
success:function(result) {
alert(result);
},
timeout:3000
});
});
jsonp:'callback',
success:function(result) {
alert(result);
},
timeout:3000
});
});
JAVA部分:
public String geGoodsPJson(){
String callback = this.getPostValue("callback");
return (callback+"("+JsonUtil.toFastJsonString(result)+")");
}
return (callback+"("+JsonUtil.toFastJsonString(result)+")");
}