jquery - Uploading a zip file using POST in Javascript fails silently -
i working on web application (using jquery version 2.2.4) allows users submit images , data our server. when users decide upload submissions, code should generate zip file using jszip library , upload our server using post. after searching here on stackexchange, came code:
var zip = new jszip(); // create object representing zip file // ...add data , images console.log('generating compressed archive...'); zip.generateasync({ compression: 'deflate', type: 'blob' }).then(function(zc) {// function called when generation complete console.log('compression complete!'); // create file object upload var fileobj = new file([zc], filename); console.log('file object created:', fileobj); $.post('http://myurl/submit', { data: fileobj, }).done(function() { console.log('ajax post successful.'); }) .fail(function(jqxhr, textstatus, errorthrown) { console.log('ajax post failed. status:', textstatus); console.log(errorthrown); }); });
my code prints file object created message, file object looks ok, nothing else. silent failure. post call not appear in net panel firebug.
after more searching, tried add code beforehand:
$(document).ajaxerror(function(event, jqxhr, settings, thrownerror) { console.log('ajax post failed. event:', event); console.log('ajax settings:', settings); console.log(thrownerror); });
but doesn't triggered. there's error making in setting callbacks errors - try?
i think don't see post
because data object doesn't contain string values (i post
if use {data: "content"}
).
following https://stackoverflow.com/a/19015673 , https://stackoverflow.com/a/18254775, need add parameters (documentation):
$.post({ url: "/test", data: fileobj, contenttype: false, processdata: false })
Comments
Post a Comment