springboot 服务端 和 前端页面都要实现跨域
服务端示例:
@ResponseBody
@CrossOrigin(origins = "*") //重点
@RequestMapping(value = "/test")
public String ss()
{
return "test+++++++8888++++++++++++++++++++++++++++++++";
}
前端示例:
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
alert(xhr.responseText);
}
}
}
xhr.open('get', 'http://localhost:8888/test', true);
xhr.send();