解决方法:
ajax 跨域请求前台处理,红色字段为ajax处理跨域属性
$.ajax({
url:"http://citygame1234.4kb.cn/CityServer/w/login",
type:"post",
async:"false",
dataType:"json",
crossDomain: true,
xhrFields: {
withCredentials: true
},
success:function(data){
console.log(data);
}
});
.net core配置
在Startup.cs类 的ConfigureServices方法加入如下代码:
services.AddCors(options =>
{
options.AddPolicy("AllowAllHeaders",
builder =>
{
builder.WithOrigins("http://localhost:63342",
"https://localhost:44395")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();
});
});
在Configure方法加入如下代码:
app.UseCors("AllowAllHeaders");
标签:core,跨域,builder,ajax,net,data,localhost
来源: https://www.cnblogs.com/xujie520/p/14250078.html