W
W
WEBIVAN2014-12-30 17:03:37
Opera
WEBIVAN, 2014-12-30 17:03:37

How to get CrossDomain Ajax to work with jQuery in Opera 12?

In chrome and FF requests work fine, in Opera 12 nothing happens in Dragonfly in the network tab of the request is not visible. What am I doing wrong?

Below is the JS code and request/response headers from chrome developer tools.
Request

$.ajax({
  url: 'index.php?route=checkout/cart/update',
  dataType: 'json',
  xhrFields: {withCredentials: true},
  success: function(json) {
    if (json['output']) {
      $('#cart .content').html(json['output']);
    }
  }
});

Request 1
OPTIONS /index.php?route=checkout/cart/update HTTP/1.1
Host: www.domain.com
Connection: keep-alive
Access-Control-Request-Method: GET
Origin: http://xn----7sbbgbcqbc3abdjei2aoows4amh5j.domain.com
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
Access-Control-Request-Headers: accept, x-requested-with
Accept: */*
Referer: http://xn----7sbbgbcqbc3abdjei2aoows4amh5j.domain.com/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4,uk;q=0.2

Answer 1
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 30 Dec 2013 13:57:58 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: http://xn----7sbbgbcqbc3abdjei2aoows4amh5j.domain.com
Access-Control-Allow-Credentials: true
ACCESS-CONTROL-ALLOW-METHOD: GET
ACCESS-CONTROL-ALLOW-HEADERS: accept, x-requested-with
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=puf1rjnecsjph77m2qnp4a5rq0; path=/; domain=.domain.com
Set-Cookie: language=Ru; expires=Wed, 29-Jan-2014 13:57:32 GMT; path=/; domain=www.domain.com
Set-Cookie: currency=UAH; expires=Wed, 29-Jan-2014 13:57:32 GMT; path=/; domain=www.domain.com
Content-Encoding: gzip


Request 2
GET /index.php?route=checkout/cart/update HTTP/1.1
Host: www.domain.com
Connection: keep-alive
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://xn----7sbbgbcqbc3abdjei2aoows4amh5j.domain.com
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
Referer: http://xn----7sbbgbcqbc3abdjei2aoows4amh5j.domain.com/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4,uk;q=0.2
Cookie: PHPSESSID=g7av0357s4ha27bakhmce2m7v5; language=Ru; currency=UAH; display=grid; path=; manufacturer_id=; _ym_visorc=w


Answer 2
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 30 Dec 2013 13:57:59 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: http://xn----7sbbgbcqbc3abdjei2aoows4amh5j.domain.com
Access-Control-Allow-Credentials: true
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Encoding: gzip

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Kitmanov, 2014-12-30
@k12th

The last time I encountered Opera 12 and cross-domain requests, it only worked through JSONP.

spoiler
И вообще у меня ощущение, что CORS там еще не поддерживался…

D
duke_pro, 2014-02-14
@duke_pro

After a long time of digging, it worked with Opera 12 (with newer ones, and so everything worked)
here is my answer to options

Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept
Access-Control-Allow-Methods:GET, POST, OPTIONS, PUT, PATCH, DELETE
Access-Control-Allow-Origin:http://mydomain.ru
Access-Control-Max-Age:1728000
Connection:keep-alive
Content-Length:0
Content-Type:application/json
Date:Fri, 14 Feb 2014 16:01:04 GMT
Server:nginx/1.4.4

in my case, the status 204 was to blame (for some reason, the opera definitely needs 200)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question