How to reset a form after submission (which is submitted using ajax)?

3 Answers 3


You can place this code in your AJAX response success

     .not(':button, :submit, :reset, :hidden')
  • can you explain
    – Jaisa
    Dec 28, 2017 at 6:01
  • 1
    I dont think there is any explanation needed for this but still since you are asking it will get all input fields with the form ID you have mentioned it will empty its value val(''), remove attributes removeAttr('checked') and removeAttr('selected') for checkbox and dropdowns and will ignore fields such as button by .not(':button, :submit, :reset, :hidden'). Hopes this helps.
    – Priyank
    Dec 28, 2017 at 6:05

You can reset it with jquery.

Use Below code


You can do this with simple javascript as well.


You can call this in ajax success method. so once your ajax call will be success it will reset the form.

  • could you please post html code of your form ? Dec 28, 2017 at 6:50
  • I have overrided the core form which is present in Magento\Review\view\frontend\templates\form.phtml. you can refer from that
    – Jaisa
    Dec 28, 2017 at 9:00

Following code works fine for me to clear form data after submission using ajax.

Please add below the jquery code after ajax success response.


Full Sample Code

    $('#quote-request-form').submit(function (event) {
        var form = $(this);
        var formData = form.serialize();

            type: 'POST',
            url: '<?php echo $block->getUrl("quoterequest/index/quoterequest"); ?>',
            data: formData,
            showLoader: true,
            cache: false,
            success: function (response) {
                $('#quote-request-form')[0].reset(); //Clear form data
                if(response.success != '')
            error: function (xhr, status, error) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.