简体   繁体   中英

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM