Answer the question
In order to leave comments, you need to log in
External Ajax request not working (Laravel), Response to preflight request doesn't pass access control check?
I execute an Ajax request to an external service to get the exchange rate in json in Laravel:
$.ajax({
url: 'https://www.cbr-xml-daily.ru/daily_json.js',
type: 'GET',
dataType: 'json',
success: function(
console.log(data);
},
});
Access to XMLHttpRequest at 'https://www.cbr-xml-daily.ru/daily_json.js?_token=arouoLREfMEpk7CypZFcYBPd9KyOCpJYPnI1qxZg' from origin 'http://mysite.exchange' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
Answer the question
In order to leave comments, you need to log in
Read about CORS Wikipedia
I also encountered such a problem, but I don’t have a backend, so I got out of the situation this way: I used a CORS proxy.
$.ajax({
type:'POST',
url: 'https://cors-anywhere.herokuapp.com/http://************.ru/api/',
data: {
query: '{"ask":"'+message+'","userid":'+id+',"key":"1"}'
},
success: function(data){
msg = JSON.parse(data);
$(".messages").append('<li><div class="text-msg receive_msg">'+msg['aiml']+'</div></li>');
while($(".messages li").length > 7){
$('li:first').detach();
}
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question