Clear fields with Ajax

0

Colleagues.

I've taken a project that already has PHP / Ajax triggered, the triggering normally occurs, but the fields are not cleared after the shot. I already tried putting form.value (); but it still does not work. Here is the code:

/* Contact form ajax Handler
    ================================================*/

    $(".ajax-form").on('submit', function() {
        var form = $(this);
        var formURL = $(this).attr("action");
        var postData = $(this).serializeArray();

        $.ajax({
            url: formURL,
            type: 'POST',
            data: postData,
            dataType: 'json',

            success:function(data, textStatus, jqXHR){

                if(data.success==1){

                    form.find(".alert").fadeOut();
                    form.find(".alert-success").html(data.message);
                    form.find(".alert-success").fadeIn(600);


                }else{

                    form.find(".alert").fadeOut();
                    form.find(".alert-danger").html(data.message);
                    form.find(".alert-danger").fadeIn(600);

                }
            },

            error: function(jqXHR, textStatus, errorThrown)  { 

                console.log(errorThrown);
            }

        });


        return false;
     })
    
asked by anonymous 13.10.2016 / 02:44

1 answer

1

Do so, the command to clear the form in case would be this

$('.ajax-form')[0].reset();

Just put in the part you want to perform this function I do not know if I believe it is within the scope of success

This command would also serve

$(".ajax-form").trigger('reset');
    
13.10.2016 / 02:52