1

can you please tell me how to read file from folder in jQuery ?Actually I have one folder name "Test" on desktop and inside that I have one file "VoipMosMO#" file.I need to read content of that file. I am able to read content when I make url(external url) of that file in fiddle.And content is display now I want to get content of that when It is on my pc "Desktop" location inside the folder. ? fiddle

jQuery.get("abc", function(data) {
   alert(data);
   //process text file line by line
   $('#div').html(data.replace('n','<br />'));
});
Shruti
  • 1,554
  • 8
  • 29
  • 66
  • 2
    You can't make Ajax requests to external locations if the server doesn't allow it. I'm relatively certain that Dropbox does not allow it. If you want to access Dropbox files via JS, you should probably use their SDK. Or maybe something like https://www.dropbox.com/developers/datastore. – Felix Kling Jun 24 '14 at 03:00
  • I need to read file from my desktop not from server – Shruti Jun 24 '14 at 03:02
  • 1
    Ah, then the answer is even simpler: You can't. (and actually I'm surprised that Dropbox lets you make that Ajax request, but it's true, when you make an Ajax request, it sets `Access-Control-Allow-Origin:"*"`) – Felix Kling Jun 24 '14 at 03:03
  • Mean I cann't read file text from my internal project directory ? – Shruti Jun 24 '14 at 03:04
  • Not if the code runs in the browser. That would be huge security risk. You can have a UI that lets you select the file and then read its content, but you can't read the file automatically. – Felix Kling Jun 24 '14 at 03:05
  • ok...!!! But I saw in mobile Project which run on device .I can read file text file from internal memenory – Shruti Jun 24 '14 at 03:06
  • Haha, then you can use javascript and you will read Peoples files with sensitive data,Do u think javascript/jquery will alone allow you to do so ? NO – Pratik Joshi Jun 24 '14 at 03:07
  • I don't want read automatically.I wiill give the path of my file directory "you can't read the file automatically." – Shruti Jun 24 '14 at 03:07
  • Mean there is no way to to read file if I give hard coded path my code – Shruti Jun 24 '14 at 03:11
  • Maybe you are looking for https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications (Google helped). – Felix Kling Jun 24 '14 at 03:12

2 Answers2

0

You can use FileReader api but it supports from IE10+

Other than that, ajax requests have no access to the platform details.

May be you can upload your file to the server and access the url from that server.

Else force the user to enter the path of the file and pass that file path to the server and read the file and show it in the client.

Bharath
  • 519
  • 4
  • 7
0

You cannot access client file or folder using java script. You need something like applet, flash or active x application to do it

user3309301
  • 301
  • 1
  • 4