0

How could I use the jQuery AJAX method to request binary files from a server. In my case, I'd like to call an MP3 file into an app that I'm working with. Do I have to encode this into base64, retrieve it as a string, and then decode it? Or is there a better way? Can I call the MP3 file directly in the url property?

Thanks!

shmuli
  • 5,086
  • 4
  • 32
  • 64

1 Answers1

1

It's not about AJAX. You can download a file with AJAX, of course. However the file will be kept in memory, i.e. you cannot save file to disk. This is because JavaScript cannot interact with disk. That would be a serious security issue and it is blocked in all major browsers.

Source

Community
  • 1
  • 1
Mangesh Parte
  • 2,179
  • 1
  • 13
  • 16
  • I'm working with PhoneGap and PhoneGap allows JavaScript to read and write to local storage. How would I go about with this? Request file, store on local hd, and play from local storage? – shmuli Dec 09 '14 at 09:23
  • 1
    You should check this link. May be this will solve your purpose: http://stackoverflow.com/questions/6417055/download-files-and-store-them-locally-with-phonegap-jquery-mobile-android-and-io – Mangesh Parte Dec 09 '14 at 09:25