Skip to content Skip to sidebar Skip to footer

How To Access Local Folders In Ajax Using File:///f:/foldername ? But It Works For Http://

Here I dynamically creating a file name list using AJAX jQuery using following code! $(window).load(function () { var fileExt = '.csv'; $(document).ready(function () {

Solution 1:

You can't.

Most browsers will block access (by XMLHttpRequest) to the local file system entirely, and those that don't do not provide a mechanism for reading directories.


For example:

Chrome says:

XMLHttpRequest cannot load file:///Users/me/tmp/. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

Firefox says:

NS_ERROR_DOM_BAD_URI: Access to restricted URI denied

… although for a file rather than a directory, it will list the content (providing the file is in or under the same directory as the HTML document).


But f:///foldername can able to access in browser. But not able access in js ! Why?

Giving access to data on your hard disk to you, as the person controlling the browser, is different from giving access to that data to some JavaScript in a file that you might have downloaded from anywhere and which might do anything with it (such as sending it to the person who wrote the JS). See also this question.

Post a Comment for "How To Access Local Folders In Ajax Using File:///f:/foldername ? But It Works For Http://"