方法1. jsonp实现ajax跨域访问示例
jsp代码:
js代码:
functiontestJsonp(){
$.ajax({
type :'GET',
dataType :'jsonp', //数据类型配置成jsonp
jsonp : "callback", //配置jsonp随机码标签,在服务器代码部分需要用到他来拼接一个json的js对象
url : 'http://127.0.0.1:8001/test', //服务路径
async : false,
data: {"type":'0',
},
success :function(response) {if(response.code == 200){
alert('返回成功!');
}else{
alert('服务器异常!');
}
},
error :function(){
alert('服务器异常!');
}
});
}
java代码:
@RequestMapping(value = "/test", method =RequestMethod.GET)public @ResponseBody String testJsonp(@RequestParam(value = "type", defaultValue = "&#