XMLHttpRequest跨域资源共享 CORS

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();

猜你喜欢

转载自blog.csdn.net/qq_35674193/article/details/103200739