Reputation: 18594
I want to load a simple txt-file from my local machine with jQuery.
When doing:
$.ajax({
method : "GET",
url : "folder/file.txt",
dataType : 'text',
success : function(data) {
console.log(data)
}
});
I get:
XMLHttpRequest cannot load file:///home/user/path/to/file/data/file.txt. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
But how is this possible, when both files (the JavaScript and the txt) are in the same directory on my local machine?
Upvotes: 1
Views: 61
Reputation: 146
If this is a quick test you are performing, then a quick solution would be to use a different browser. For instance, Firefox runs that piece of code just fine.
Upvotes: 0
Reputation: 943193
Chrome considers all XMLHttpRequest requests to file:
URIs to be cross-origin.
If you want to use XMLHttpRequest, then run an HTTP server.
Upvotes: 1