1

how do I delete all the contents of the fields in the form, if I use ajax to post to the controller

    <form id="addform">

     $("#btnadd").on("click",function(){
    $(this).attr('disabled','disabled');
        var tampung = $("#addform").serialize();
        $.ajax({
               type: "POST",
               url: "{{route('add-form')}}",
               data: tampung,
               dataType: "json",
               success: function(response) {
                if(response.validator == 'error'){
                    $("#btnadd").removeAttr('disabled');
                }
                if(response.status){
                    createAlert(response.status, "success");
                    $(".close").trigger('click');
                    $("#btnadd").removeAttr('disabled');
//there i need refresh form
                    VendorClient.ajax.reload(null, false);
                }
        });
   });
Newbie 123
  • 254
  • 4
  • 19
  • Does this answer your question? [How to reset a form using jQuery with .reset() method](https://stackoverflow.com/questions/16452699/how-to-reset-a-form-using-jquery-with-reset-method) – user11657407 Jan 16 '20 at 04:26

2 Answers2

1

You can use document.getElementById("addform").reset(); to reset a form

Nate
  • 397
  • 5
  • 16
1

Using jQuery you can trigger a reset.

$('#addform').trigger("reset");

Another alternative to reset the form:

$("#addform")[0].reset();
user11657407
  • 312
  • 2
  • 12