AJAX request for a local file system not working in Chrome?

I am working on dynamically creating a user interface from XML using jQuery. My jQuery works in Firefox, but it doesn't work in Chrome. This gives me this console error:

Cross-start requests are supported only for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

The following is jQuery code that works in Firefox but does not work on Google Chrome:

$.ajax({ url: 'file:///home/satendra/dndExamples/avisDnD/file.xml', success: function(xml) { $(xml).find('Tab').each(function() { var id = $(this).attr('URL'); var tab = $(this).attr('TabName'); $("ul").append("<li><a href="+ id +">"+ tab +"</li>"); }); } }); 
+5
source share
1 answer

Firefox allows the request because it accepts requests to the local file system (i.e. the file:// protocol) if they also come from it. However, Chrome denies all XMLHttpRequests to file:// urls.

Please note that you cannot make an AJAX request to the local file system from an external domain in any browser - this would be a serious security flaw if you could.

For this AJAX request to work in Chrome, you need to make a request to the web server. If you are on Windows, you can easily install IIS or WAMP on your local computer.

Please note that you can enable the setting in Google Chrome, which allows you to query the local file system in the browser, but it is not recommended to use it. If you decide that you want to go further and do it anyway, the guide can be found here .

+10
source

All Articles