5

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?

4
  • I am also experiencing this problem. And it works fine in Incognito and Firefox like you said. I hope someone can offer an explanation/solution. Commented Feb 16, 2014 at 21:37
  • Hi Kevin, i still looking for a solution. The issue also occurs in the latest Canary Build of Chrome. Commented Feb 27, 2014 at 10:02
  • Have you already found a solution? I even tried a plain XMLHttpRequest() -> same result Commented Mar 17, 2014 at 16:42
  • Unfortunately no, I've just been using chrome in incognito as a workaround. Commented Mar 19, 2014 at 19:20

2 Answers 2

7

I had the same problem. After I disabled the option "Predict network actions to improve page load performance" in Chrome's advanced settings the delay was gone.

Sign up to request clarification or add additional context in comments.
0

Maybe you can add the next headers to your ajax request.

headers: {
    "Cache-Control" : "no-cache, no-store, must-revalidate",
    "Pragma": "no-cache",
    "Expires", "0"
}

Your Answer

Draft saved
Draft discarded

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.