处理response设置cors返回头部信息
服务端代码:
string action = Request.QueryString["action"]; Response.ContentType = "text/json"; var origin = Request.Headers["Origin"]; if (!string.IsNullOrEmpty(origin) && origin.Contains("自己的域名")) { Response.AppendHeader("Access-Control-Allow-Origin", origin); Response.AppendHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS"); Response.AppendHeader("Access-Control-Allow-Headers", "*"); Response.AppendHeader("Access-Control-Allow-Credentials", "true"); }
前端代码:
$.ajax({ url: '//callfee.aspx', type: 'post', xhrFields: { withCredentials: true }, success: function (res) { if(res.Status==0){ }else{ } } })