to submit a form among multiple forms using jquery-ajax

和自甴很熟 提交于 2019-11-30 07:07:54

You need to reference the form with this when you serialize it...

$(function () {
    $('form').on('submit', function (e) {
        $.ajax({
            type: 'post',
            url: 'addfr.jsp',
            data: $(this).serialize(),
            success: function () {
                location.reload();
            }
        });
        e.preventDefault();
    });
});

Use this keyword. It will submit the form on which the event has been triggered.

why are u using location.reload?

$('form').on('submit', function (e) {
    $.ajax({
    type: 'post',
    url: 'addfr.jsp',
    data: $(this).serialize(),
    success: function () {
        location.reload();
    }
 });
 You can try this...

 function submitForm(){
document.formName.action="actionName";
document.formName.submit();
 }


 <form method="post" name="formName" enctype="multipart/form-data">
  ....
 <input type="button" onclick="submitForm()"/>
 <form>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!