I'm doing a registration via ajax, and I'm getting the following error: Request header field X-Requested-With Access-Control-Allow-Headers in preflight response.
Do not register, 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 workaround to fix and how do I do it?
Att,
Alisson