I am trying to Update/Insert data in a MySQL database through a PHP backend. I'm building the Front End with AngularJS and using the $http
service for communicating with the REST API.
My setup looks like this:
I'm setting the header via the $httpProvider:
$httpProvider.defaults.withCredentials = true;
$httpProvider.defaults.headers = {'Content-Type': 'application/json;charset=utf-8'};
And the POST-Call looks like this:
return $http({
url: url,
method: "POST",
data: campaign
});
The Dev Console in Chrome shows me this:
When I change from POST to PUT, I'm sending an OPTIONS call instead a PUT. And the content-type switches just to content-type
.
My request payload is send as an object:
How do I set my header properly?
EDIT:
The PHP backend sets some headers:
$e->getResponse()
->getHeaders()
->addHeaderLine('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
$e->getResponse()
->getHeaders()
->addHeaderLine('Access-Control-Allow-Origin', '*');
Is there something missing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…