php - AJAX FormData Post - 503 Service Unavailable -
i've searched extensively on problem without avail or maybe i'm missing issue. please, relay me improve on explanation.
i have 'file' input calls php file using ajax on 'change' so:
$(document).on('change', 'input[name="photo"]', function(){ var file = this.files[0]; var formdata = new formdata(); var user = localstorage.getitem("user"); formdata.append('_file', file); formdata.append('_user', user); $.ajax({ type: "post", cache: false, url: ip + "php/insert_img.php", data: formdata, contenttype: false, processdata: false, success: function (e) { // }, error: function (jqxhr, textstatus, errorthrown) { alert(textstatus, errorthrown); } }); });
this supposed phonegap app, , i'm using chrome's ripple emulator apache cordova/phonegap platform enabled testing.
now, works it's supposed when using localhost, , php prints formdata should, however, when use same php file uploaded server (hence 'ip' variable on ajax's url option), thats different story.
after sometime returns error setting , when checking chrome's developer tools > network tab, can see 'status code' of request is: 503 service unavailable. but, if change data setting other formdata(), works.
seems issue comes server settings, not aware of problem be.
i have experienced problem many of times when using ajax here initial thoughts:
is "ip" defined? url: ip + "php/insert_img.php"
also found removing of ajax options fixed issue. amended code below:
$(document).on('change', 'input[name="photo"]', function(){ var file = this.files[0]; var formdata = new formdata(); var user = localstorage.getitem("user"); formdata.append('_file', file); formdata.append('_user', user); $.ajax({ type: "post", url: ip + "php/insert_img.php", data: formdata, success: function (e) { // }, error: function (jqxhr, textstatus, errorthrown) { alert(textstatus, errorthrown); } }); });
hope helps.
---------- edit ----------
after bit of searching around, believe issue you're appending _file
, _user
data. if values of data array have "stringify" it:
formdata.append('_file', json.stringify(file)); formdata.append('_user', json.stringify(user));
Comments
Post a Comment