Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Received an invalid response. Origin 'null' is therefore not allowed access

Tags:

javascript

I am following a book example hence the code is very simple. This is the code:
I see an error in Chrome console:

$(function() {
    $(".lang").change(function(){

    var element = $(this);

    var id = element.attr("value");

    if(id == 'english')
    {
        $.ajax({
            type: "GET",
            url: "jsfiles/english.js",
            dataType: "script"
        }); 
    }

    return false;

    });

});
like image 464
chetan Avatar asked Jun 30 '14 13:06

chetan


People also ask

How do I fix null has blocked by CORS policy?

How do I fix origin Null has blocked by CORS policy? From Origin 'null' Has Been Blocked By CORS Policy Error. To fix this error is also easy, what you need to do is to create a local web server, and then upload the Html and JS file to the webserver.

What does Access-Control allow origin null mean?

Access-Control-Allow-Origin: null This value should not be used to serialize the origin of resources that use a non-hierarchical scheme. Sandboxed documents are defined as null. User agents may grant access to these documents and create a hostile document with null origin.

Why is request origin null?

If a cross-origin resource redirects to another resource at a new origin, the browser will set the value of the Origin header to null after redirecting.

Why is Origin header null in request?

The Origin spec indicates that the Origin header may be set to "null". This is typically done when the request is coming from a file on a user's computer rather than from a hosted web page. The spec also states that the Origin may be null if the request comes from a "privacy-sensitive" context.


1 Answers

Origin null means you are loading the HTML document directly from your file system. You can't use XMLHttpRequest without HTTP.

Either install a web server for your development, or dynamically generate a <script src="..."></script> instead.

like image 127
Quentin Avatar answered Sep 17 '22 18:09

Quentin