please also check my updates on the bottom
I do have some problems performing a Cross-Domain jQuery.ajax GET REQUEST in Chrome.
The pre-fight is pending extremely long (up to 20seconds) while it works well in Firefox.
I tried different tips (e.g enabling async) but I can't manage that. The response is an json object array and not very large (only a few bytes).
The problem seems to be on the first call only. I made a function that performs the request again. Its executed by the success handler. After the first delay from min 12 seconds the request performs normal.
I already tried different versions of jQuery (as Iam using 2.0.3 for the first time).
I logged the server. As as imagined he OPTION request is not performed for up to 20s. There is no server issue. The server recognizes the command exactly according to the delay and performs the GET method .
For a Page loaded 2014-01-11 14:59:00 my log outputs following:
2014-01-11 14:59:14 - log.txt - "OPTIONS /unit/IO/*?_=1389452340572 HTTP/1.1" 200 -
2014-01-11 14:59:14 - log.txt - "GET /unit/IO/*?_=1389452340572 HTTP/1.1" 200 -
2014-01-11 14:59:14 - log.txt - "OPTIONS /unit/IO/*?_=1389452340573 HTTP/1.1" 200 -
2014-01-11 14:59:14 - log.txt - "GET /unit/IO/*?_=1389452340573 HTTP/1.1" 200 -
This is my ajax call:
$.ajax({
url: <<crossdomain>>,
type: 'GET',
contentType:'application/json',
async:true,
cache:false,
beforeSend: function (request)
{
request.setRequestHeader("Authorization", 'Basic ' + encodedData);
},
success: function(response) {
alert(response)
}
});
Request header (Chrome):
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Access-Control-Request-Headers:accept, authorization, content-type
Access-Control-Request-Method:GET
Cache-Control:max-age=0
Connection:keep-alive
DNT:1
Host:<<crossdomain>>
Origin:<<thisdomain>>
Referer:<<directpathonthisdomain>>
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
Respond header (Chrome):
Access-Control-Allow-Headers:Authorization
Access-Control-Allow-Headers:Accept
Access-Control-Allow-Headers:Content-Type
Access-Control-Allow-Headers:Accept-Language
Access-Control-Allow-Methods:POST, GET, OPTIONS
Access-Control-Allow-Origin:*
Cache-Control:no-cache
Content-Type:application/json
Date:Sat, 11 Jan 2014 13:28:32 GMT
Server:Python3.2
This is the network traffic for the first call:
Chrome:
OPTION
DNS Lookup: 0 ms
Connecting: 3 ms
**Waiting: 17.44s**
Receiving 2 ms
GET
DNS Lookup: 0 ms
Connecting: 2 ms
Sending: 0 ms
Waiting: 46 ms
Receiving 1 ms
For comparison the Firefox log:
OPTION
DNS Lookup: 0 ms
Waiting: 10 ms
Receiving 5 ms
GET
DNS Lookup: 0 ms
Waiting: 41 ms
Receiving 3 ms
EDIT: There is no issue if Iam opening the html file directly (file:///) and not hosted on a local/remote server.
EDIT 2: It works in chrome incognito mode - may a caching issue?