javascript - Unable to submit form data using ajax() post -
i submit form data using $.ajax()
method, data contains image files. while submitting encountered below issues:
- form not getting submitted in ie10,11
- though submitting in chrome , ff,
ajax()
executing both success , error methods - i able submit data in chrome , ff displaying error message
- data submitted db chrome , ff
below code using submit data
$.fn.serializeobject = function() { var o = {}; var = this.serializearray(); $.each(a, function() { if (o[this.name] !== undefined) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ''); } else { o[this.name] = this.value || ''; } }); return o; }; $(function() { $('form').submit(function() { var senddata = json.stringify($('form').serializeobject()); $('#result').text(senddata); var form_data = new formdata($(this)[0]); form_data.append('jsonstring', senddata); var settings = { "async": true, "crossdomain": true, "url": "google.com",//sample url "method": "post", "processdata": false, "contenttype": false, "headers": { "access-control-allow-origin": "*", "cache-control": "no-cache" }, "mimetype": "multipart/form-data", "cache": false, "data": form_data//, //"datatype": "jsonp" }; $.ajax(settings).done(function (data) { console.log(data); }) .success(function (data) { alert("submitted"); }) .error(function (data){ alert("failed"); console.log(data); }); return false; }); }); <!-- language: lang-html --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <form action=""> <input type="hidden" name="profiletypeid" value="112" maxlength="36" size="12"/> first name:<input type="text" name="firstname" value="hydtest" maxlength="12" size="12"/> <br/> last name:<input type="text" name="lastname" value="3sparrowtest" maxlength="36" size="12"/> <br/> email:<input type="text" name="emailid" value="jacksparrow@testmail.com" maxlength="36" size="12"/> <br/> address1:<input type="text" name="address1" value="piratestest" maxlength="36" size="12"/> <br/> <input type="hidden" name="address2" value="piratestest" maxlength="36" size="12"/> <input type="hidden" name="city" value="caribbean" maxlength="36" size="12"/> profile image: <input name="file" type="file" /><br /> <p><input type="submit" /></p> </form> <!-- end snippet -->
i think form not submitting because of images. try base64 encoding images before submitting them server.
here reference base64 encode images using javascript:
Comments
Post a Comment