hello,
I am consuming web API in post method in my project, but it gives following course error.
My API is in different project and I am consuming in different project in postman API works well, but in jquery Ajax call gives error
Access to XMLHttpRequest at 'http://localhost:62694/api/app/Post' from origin 'http://localhost:59345' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
jquery ajax
<script type="text/javascript">
//Add event handler.
$("body").on("click", "#btnAdd", function () {
//var txtName = "0FF592C4-0E7C-4D78-8847-452838791C49";
//var txtCountry = "country";
var _customer = {};
_customer.Name = "0FF592C4-0E7C-4D78-8847-452838791C49";
_customer.Country = "country";
$.ajax({
type: "POST",
url: "http://localhost:62694/api/app/Post",
data: JSON.stringify(_customer),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
alert("success");
}
});
});
</script>
<input type="button" id="btnAdd" value="Add"/>