浏览器随便打开一个地址 ,打开控制台
var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://127.0.0.1:9000/dev/tsscPlanDay/saveTSscPlanDay'); xhr.setRequestHeader("x-access-token",""); xhr.send(null); xhr.onload = function(e) { var xhr = e.target; console.log(xhr.responseText); } ƒ (e) { var xhr = e.target; console.log(xhr.responseText); }
跨域报错和不报错的区别
后端springboot处理跨域问题配置
@SpringBootConfiguration public class MyWebConfigurer implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry corsRegistry){ /** * 所有请求都允许跨域,使用这种配置就不需要 * 在interceptor中配置header了 */ corsRegistry.addMapping("/**") .allowedOrigins("*") .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") .allowedHeaders("*"); } }
标签:console,跨域,问题,xhr,报错,测试,var,log From: https://www.cnblogs.com/qq376324789/p/17022146.html