Giorgi Chitaladze
Giorgi Chitaladze

Reputation: 41

Refused to get unsafe header "Content-Length"

can anyone help?

I'm newbie here

function getFileSize(url, callback) {
        var request = new XMLHttpRequest();
        //get only header.
        request.open("HEAD", url, true);
        request.onreadystatechange = function() {
            if (this.readyState == this.DONE) {
                callback(parseInt(request.getResponseHeader("Content-Length")));
            }
        };
        request.send();
    }

Refused to get unsafe header "Content-Length"

that line gives me an error >> allback(parseInt(request.getResponseHeader("Content-Length"))); in console

can anyone help?

Upvotes: 3

Views: 16860

Answers (1)

arjabbar
arjabbar

Reputation: 6404

Your JavaScript is fine. This is a CORS issue. You can learn more from this answer here.

If you can modify the headers at the source you need to include the Access-Control-Expose-Headers header. You can read more about that here.

Upvotes: 6

Related Questions