Ajax request rejected due to Origin 'null', origin IS the same and NOT on local or local file

SOLVED ?, almost ..

This is due to how Chrome (47.0.2526.73) handles xml files. I don't know the details, but this code works fine in Firefox (43.0.4).

I'm still wondering why this is, or how to make it work in Chrome.

What am I trying to do:

Create a javascript bookmarklet to check sitemap xml links for 404s / 500s / etc.

Labeled code snippet:

    var siteMap="http://www.example.com/sitemap.xml";
    var httpPoke = function(url,callback){
        var x;
        x = new XMLHttpRequest();
        x.open('HEAD', url);
        x.onreadystatechange = function() {
            if (this.readyState == this.DONE) {
                callback(this.status);
            }
        }
        x.send();
    };  

    var response=httpPoke(siteMap,function(n){
                console.log(n);
                });

If I am on any other page in the domain, the answer is:

    200

If I go to the actual site map, http://www.example.com/sitemap.xml , the same code answers:

"Access-Control-Allow-Origin" . "null" .

- , , .

:

1) xml -. Google "filetype: xml sitemap" , XML ( , ).

2) .

3) , siteMap ​​ URL. CORS. siteMap = location.href;

, , Firefox, Chrome.

:

FROM HTML, HTML- .
FROM HTML-, XML-, .
FROM XML, HTML-, .
FROM XML, XML-, .

, :

, , () :

  • , localhost, :/// .

, .

+4
2

OK.

:

, xml Firefox Chrome ( IE, ), , , , XML-.

Chrome, (nodomain), :

/* Copyright 2014 The Chromium Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

, URL- " http://www.example.com/sitemap.xml" window.location.href " http://www.example.com/sitemap.xml", location.origin - " http://www.example.com", , (nodomain), . .

, null xml-.

.

:
Chrome Origin

Firefox , FF Origin GET HEAD , Chrome . , XML- document.domain null. , , .

, Chrome? ?

...

:

  • xml Chrome.
  • AJAX.
  • :

    Accept:*/* Accept-Encoding:gzip, deflate, sdch Accept-Language:en-GB,en-US;q=0.8,en;q=0.6 Cache-Control:no-cache Connection:keep-alive Host:www.example.com Origin:null Pragma:no-cache User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36

jaromanda-x , .

+2

http://www.example.com/sitemap.xml , , script? , . , , CORS

- XMLHttpRequest , . . , .

0

Source: https://habr.com/ru/post/1626190/


All Articles