javascript - HTML5 Upload via XHR fails in Chrome -
i using xhr upload file works great in ff fails in chrome.
an error thrown says upload failed: 0
means xhr.status comes 0
- i'm not sure means? no other status recorded.
//check if have xhr / file support if (typeof file != "undefined" && typeof (new xmlhttprequest()).upload != "undefined") { var xhr = new xmlhttprequest(); xhr.upload.onprogress = function(e){ if (e.lengthcomputable){ uploadstarted = true; var loaded = (e.loaded / e.total) * 100; showprogress(loaded); } }; xhr.onreadystatechange = function(){ if (xhr.readystate == 4){ if (xhr.status == 200){ uploadcomplete(); } else { alert("upload failed: " + xhr.status); } console.log("status",xhr.status); } }; var formelement = document.getelementbyid("configform"); xhr.open("post", $("#configform").attr('action') , true); xhr.send(new formdata(formelement)); }
an xhr.status == 0
means there some network error. specs don't how can find out error was.
i suggest log whole xhr
structure console (console.log(xhr)
). maybe 1 of other fields contains valuable data.
if fails, check error logs of server. maybe wrong on server side.
Comments
Post a Comment