Answer the question
In order to leave comments, you need to log in
Why doesn't cross domain request work?
Good day to all, I'm trying to make a cross domain request, I'm
testing in Firefox Quantum
$.ajax({
url: url,
xhrFields: {
withCredentials: true
},
success: function(data) {
data = JSON.parse(data);
console.log(data);
if (data.length == 0) {
console.log('Came an empty array');
$("detailing").html(' <div class="row"><div class="col-sm-12"><center><h3>Нет детализации</h3></center></div></div>');
}
}
});
Host: parser.test1.isan.pro
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost/index.php/admin/phones
Origin: http://localhost
DNT: 1
Connection: keep-alive
HTTP/1.1 200 OK
Date: Fri, 14 Dec 2018 06:06:15 GMT
Server: Apache/2.4.18 (Ubuntu)
Cache-Control: no-cache, private
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, OPTIONS, HEAD
X-Debug-Token: 78a6a1
X-Debug-Token-Link: http://example.pro/index.php/_profiler/78a6a1
Content-Length: 2
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/json
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, OPTIONS, HEAD
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at example.pro/index.php/api/phone?number=96176214270 . (Reason: CORS header 'Access-Control-Allow-Origin' does not match '*').[More]
Answer the question
In order to leave comments, you need to log in
you have the option withCredentials: true - which tells the browser that you want to send cookies to a third party resource. In this regard, a stricter CORS policy:
1. the response header Access-Control-Allow-Origin cannot be a wildcard (*), the server must respond with the exact origin
2. the response header Access-Control-Allow-Credentials: true must be present
on the total server should respond with the following headers:
Access-Control-Allow-Origin: {request.headers.Origin}
Access-Control-Allow-Methods: GET, OPTIONS, HEAD
Access-Control-Allow-Credentials: true
where {request.headers.Origin} - Origin header from the request
Google Chrome?
he has problems, for example, with loading Ajax from a local file
, you need to cut down some fad in deep settings
put it in the handler at the very beginning header('Access-Control-Allow-Origin: *');
and send jsonp
helped me
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question