setup custom header:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="*" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
Server cài đặt:
Install-Package Microsoft.AspNet.WebApi.Cors
cấu hình: https://csharp-video-tutorials.blogspot.com/2016/09/cross-origin-resource-sharing-aspnet.html
EnableCorsAttribute cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors();
---------------------------------------
Gọi Ajax:
$.ajax({
type: "POST",
url: 'change-your-url',
cache: false,
contentType: "application/x-www-form-urlencoded; charset=utf-8",
dataType: "json",
success: function (res) {
console.log(res);
},
error: function (xhr, textStatus, errorThrown) {
console.log(xhr, textStatus, errorThrown);
}
});