0

I'm trying to download content through XHR post and save it locally, so I tried to restore recieved data into a blob object as a file but a jscript error is fired saying that blob is undefined !

window.URL = window.URL || window.webkitURL;
$.ajax({
url: 'CreateFile.aspx',
type: 'POST',
data: { 'param1': "verylargedata1",
    'param2': "verylargedata2"
},
headers: {
    "accept": 'application/octet-stream',
    "content-type": 'application/x-www-form-urlencoded',
    "X-RequestDigest": $("#__REQUESTDIGEST").val()
},
error: function (xhr, ajaxOptions, thrownError) {
    alert(xhr.status);
    alert(thrownError);
},
success: function (data) {
    var blob = new Blob(data, { 'type': "application/octet-stream" }); //Jscript error undeined blob
    var url = window.URL.createObjectURL(blob);
    iframe.src = encodeURI(url);
}
});
Jojo GKH
  • 57
  • 3
  • 7

1 Answers1

2

It is not supported in many browsers. I am guessing you are using IE9 or under since it says JScript in the error message. IE10 has some support.

For current browser support check out: http://caniuse.com/#search=blob

epascarello
  • 204,599
  • 20
  • 195
  • 236
  • yeah you're right,but if i may ask: do you know any other way to restore recieved data (written in the response object in the CreateFile.aspx as a text file ) in the success function or just download it directly, PS: I can't use iframe.scr(url) or window.location ( because the url size is beyond the limit) – Jojo GKH Feb 01 '13 at 15:23
  • why are you not just posting the form to the iframe? – epascarello Feb 01 '13 at 15:29
  • because I'm passing data with a huuuge size and the url in the iframe is limited – Jojo GKH Feb 01 '13 at 16:10
  • I found this answer for whoever is wandering http://stackoverflow.com/questions/7578124/jquery-ajax-call-for-pdf-file-download – Jojo GKH Feb 03 '13 at 22:39