1
I am making a registration via ajax, and I am getting the following error: Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers in preflight.
You don’t register, you follow my codes:
var dataString = $(this).serialize();
$.ajax({
url: "<?= BASE; ?>/modulos/index.php",
type: 'POST',
cache: false,
crossDomain: true,
dataType: 'jsonp',
data: 'action=enviar_ordens&' + dataString,
beforeSend: function (data) {
$('.msg_error').html('<div class="alert alert-info">Aguarde estamos enviando seu pedido...</div>');
$("#btn_order").attr('disabled', true);
$('#btn_order').text("AGUARDE UM MOMENTO...").attr({
title: "Aguarde... Enviando pedido!"
});
},
success: function (data) {
if (data.code == 'success') {
$('.msg_error').html('<div class="alert alert-' + data.code + '">' + data.msg + '</div>');
$("#btn_order").attr('disabled', false);
$('#btn_order').text("Enviar Pedido").attr({
title: "Enviar Pedido"
});
} else {
$('.msg_error').html('<div class="alert alert-' + data.code + '">' + data.msg + '</div>');
$("#btn_order").attr('disabled', false);
$('#btn_order').text("Enviar Pedido").attr({
title: "Enviar Pedido"
});
}
},
error: function (data) {
console.log(data);
}
});
In my PHP I put this:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
I wonder if there is a simple solution to fix and how I do?
Att,
Alisson
my BASE constant I put without www. and is configured with https://,
– Alisson Maciel
Mistakes are gone, but now my request doesn’t work
– Alisson Maciel
@Alissonmaciel "does not work" is quite ambiguous, don’t you agree? Have a look at the browser console and see if any errors have occurred.
– Guilherme Nascimento
Well, I switched the header you reported in php, removed the crossdomain, removed the cache and changed the datatype to json, and now it’s back up and running, even though it’s the way it is. I suppose, that the problem was really the header, and as I modified the jquery code, to try to fix, gave problem, more I had to change only the header and leave the code as it was, finally, came back to work and thanks for the solution!
– Alisson Maciel