1,关于跨域带cookie
在服务端增加跨域:
spirng 配置:非常方便。
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowCredentials(true).maxAge(3600);
}
}
相当于 增加 filter 了:
response.addHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
2,在客户端使用jquery进行测试
var jq = document.createElement('script');
jq.src = "https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
$.ajax({
type: "GET",
url: "http://blog.youkuaiyun.com/zhangsan",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
然后就可以进行测试了。
这样就是不支持跨域。
3,公共js cdn
http://www.staticfile.org/
七牛提供的。