How to opt out of preflight response in AngularJS
When submitting a http.post request to my service, I first submit an Option request (as required by Cors).
However, I realized that my OPTIONS request (before flight) is not returning response.data
in my response, but my POST request . This creates a problem as I need to access response.data
from the POST response ...
Does Angular allow you to cancel OPTIONS response in a call http.post
?
$http.post("http://api.worksiteclouddev.com/RestfulAPI/api/vw_PeopleListSiteAccess_Update/Get/", JSON.stringify(vm.content))
.then(function (response) {
//success
vm.person = {
"firstname": response.data.Firstname,
"surname": response.data.surname
};
console.log(response.data);
},
function (error) {
//failure
console.log("Something went wrong..." + error.status);
})
.finally(function () {
vm.ptsnumber = "";
});
source to share
You cannot cancel an OPTIONS request.
The purpose of this request is to ask the server for permission to make the actual request. Your preflight response must validate these headers for the actual request to work.
They are necessary when you are making requests from different origins.
This pre-request is performed by some browsers as a security measure to ensure that the request being made is trusted by the server. Server Meaning understands that the method, source, and headers sent on request are action-safe.
In your case, you should get the answer here in the post api response
$http.post(
"http://api.worksiteclouddev.com/RestfulAPI/api/vw_PeopleListSiteAccess_Update/Get/", JSON.stringify(vm.content)
).then(function (response) {
console.log(response.data);
//You should get your response here
},
function (error) {
console.log("Something went wrong..." + error.status);
});
// For more information you can create an external service and call the api on that service
// in your controller you can call this method
source to share