Answer the question
In order to leave comments, you need to log in
Why is the CORS header missing in Laravel when sending an AJAX request?
Hey!
Sending an AJAX request like this:
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': "{{ csrf_token() }}"
}
});
$.ajax({
url: "https://www.example.ru/confirm",
type: "post",
data: {type: "Customer", order_id: order_id},
dataType: "json",
error: function (err) {
console.log(err);
}
});
});
Request from foreign source blocked: The single origin policy prohibits reading the remote resource at https://example.ru/confirm . (Reason: missing CORS header "Access-Control-Allow-Origin").
Answer the question
In order to leave comments, you need to log in
Use the ready-made middleware - \Fruitcake\Cors\HandleCors::class + by specifying the desired route in the config, as described here https://github.com/fruitcake/laravel-cors in the Global Usage section.
If it starts up, then you can figure out what was wrong with your middleware.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question