I am trying to use jquery ajax to download a binary audio file.
Normally, I would simply issue this command:
windows.location.href = 'http://marksdomain(dot)com/audioFile.wav' ;
However, recently our server has been waiting for a response too long, and I get an unpleasant message about the gateway timeout.
It has been suggested that I use jquery-ajax instead, which makes sense since I have more control over the timeout.
Here is the code I've played so far:
$.ajax( { url: 'http://marksdomain(dot)com/audioFile.wav' , timeout: 999999 , dataType: 'binary' , processData: false // this one does not seem to do anything ? , success: function(result) { console.log(result.length); } , error: function(result, errStatus, errorMessage){ console.log(errStatus + ' -- ' + errorMessage); }
When I omit "dataType", the binary goes about three times as much as it actually does on the server. However, when I make dataType equal to binary, ajax throws an error:
"No conversion from text to binary"
From some early posts, it sounds like jquery-ajax cannot handle binary files this way.
I found Delivery.js that really works well enough for what I'm trying, but I would prefer not to use the node solution if possible.
Any suggestions?
javascript jquery ajax
edwardsmarkf
source share