3
I’m making my api, in php, and I get the following warning
Xmlhttprequest cannot load http://vigilantescomunitarios.com/serviapp/api_gustavo/register.php. Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight.
Follow the beginning of my php code:
<?php
header("Access-Control-Allow-Origin: *");
ini_set('display_errors', true);
error_reporting(E_ALL);
include_once("conexao.php");
$pdo = conectar();
$data = file_get_contents("php://input");
$data = json_decode($data);
$eh_profissional = $data->is_professional;
Follow my controller:
angular.module('servi.controllers', ['ngCordova'])
.controller('cadastroCtrl', ['$scope', '$stateParams', '$http',
$cordovaSQLite', '$window', '$state', function ($scope, $stateParams, $http,
$cordovaSQLite, $window, $state) {
$scope.email = [];
$scope.cadastrar = function(usuario){
$http.post("http://vigilantescomunitarios.com/serviapp/api_gustavo/register.php", usuario).success(function(response){
// http://vigilantescomunitarios.com/serviapp/api/register
})
}
}])
Anybody know what the problem is? Thank you.
My case is different... I am accessing an external url and not local.
– GustavoSevero
I agree with Gustavo, the error is another... Gustavo the message says that when trying to send a request with the header
Content-Type
(maybe an ajax) it was not released onAccess-Control-Allow-Headers
, I’m looking to see if you have an answer to that. PS: title reversed, I think you already have enough experience on the site to understand the usefulness of the question title to make it useful to future visitors.– Guilherme Nascimento
@Gustavosevero and Guilherme, vote withdrawn.
– Marconi
@diegofm is not the same error, although being related the problem is specifically the behavior of
XMLHttpRequest.setRequestHeader('Content-Type', 'valor customizado')
(ajax), the 3 values accepted areapplication/x-www-form-urlencoded
,multipart/form-data
andtext/plain
, but JS libs like Angular and jQuery usually useapplication/json
what is not standard.– Guilherme Nascimento