AJAX: Submitting a form without refreshing the page

前端 未结 8 2019
感动是毒
感动是毒 2020-11-30 11:43

I have a form similar to the following:

8条回答
  •  天涯浪人
    2020-11-30 12:19

    try this:

    $(function () {
        $('form').submit(function () {
            if ($(this).valid()) {
                $.ajax({
                    url: this.action,
                    type: this.method,
                    data: $(this).serialize(),
                    success: function (result) {
                        $('#result').html(result);
                    }
                });
            }
            return false;
        });
    });
    

提交回复
热议问题