html - Reset jquery mobile form input after submit -


i got form in jquery mobile framework, , want reset value of input fields after have been submitted. tried search around here solutions, can't figure out how make work proper.

jquery:

$(document).ready(function () {     $("#add").submit(function () {         var formdata = $(this).serialize();          $.post('save.php', formdata, processdata).error(errorresponse);          function processdata(data) {             $("#popupsave").popup();             $("#popupsave").popup("open");         };         function errorresponse() {             alert("something went wrong!");         };         return false;     }); }); 

form:

<form id="add">   <div data-controltype="textblock">     <p>       text     </p>   </div>   <div class="ui-field-contain" data-controltype="textinput">     <input name="vegetables" id="textinput1" placeholder="300g" value="" type="number">   </div>   <div data-controltype="textblock">     <p>       text     </p>   </div>   <div class="ui-field-contain" data-controltype="textinput">     <input name="fullgrain" id="textinput2" placeholder="30g" value="" type="number">   </div>   <div data-controltype="textblock">     <p>       text     </p>   </div>   <div class="ui-field-contain" data-controltype="textinput">     <input name="milk" id="textinput3" placeholder="200ml" value="" type="number">   </div>   <div data-controltype="textblock">     <p>       text     </p>   </div>   <div class="ui-field-contain" data-controltype="textinput">     <input name="water" id="textinput4" placeholder="300ml" value="" type="number">   </div>   <input type="submit" value="tilføj">   <input type="reset" value="nulstil" />   <div data-role="popup" id="popupsave" class="ui-content">     <p>text</p>   </div> </form> 

try then:

$(document).ready(function () {     $("#add").submit(function () {         $this = $(this);         var formdata = $this.serialize();          $.post('save.php', formdata, function (data) {             $("#popupsave").popup();             $("#popupsave").popup("open");             $this.find("input").val("");         }).error(errorresponse);          function errorresponse() {             alert("something went wrong!");         };         return false;     }); }); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -