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;
});
});
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With