如何使用Ajax进行jquery表单提交?

时间:2022-11-23 14:19:50

In my java application I'm submitting the form using JQuery.

在我的java应用程序中,我使用JQuery提交表单。

Here is the code in my jsp:

这是我的jsp中的代码:

    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<fieldset id="profile_proffiesional">
    <form:form action="profile/awards" modelAttribute="AWARDS">
        <p>
            <label for="position">Position</label>
            <form:input path="position" tabindex="4" />
        </p>
        <p>
            <label for="location">Location</label>
            <form:input path="location" tabindex="5" />
        </p>
        <p>
            <label for="description">Description</label>
            <form:input path="description" tabindex="5" />
        </p>
        <p>
            <input type="submit" value="Add">
        </p>
    </form:form>
</fieldset>
<script>
    $('#AWARDS').ajaxForm({
        target : '#body',
        success : function(responseText, statusText, xhr, $form) {
            alert(responseText);
        },
        beforeSubmit : function() {
            $.blockUI({
                message : '<h1> Just a moment...</h1>'
            });
        }
    });
</script>

Problem is when I click Submit button, where the form goes and it shows the response with alert. When I click OK button in alert window, the same success message will get printed on window, in the place of form.

问题是,当我单击“提交”按钮时,表单将显示,并显示带有警报的响应。当我在警报窗口中单击“确定”按钮时,相同的成功消息将打印在窗口上,形式上。

And the Form gets totally invisible, when I refresh it and the success message will be removed and the form is shown.

当我刷新它时,表单变得完全不可见,并且将删除成功消息并显示表单。

But I want to display success on alert and not on the screen. Please help me on this.

但我希望在警报上显示成功,而不是在屏幕上显示。请帮帮我。

1 个解决方案

#1


0  

Removing target : '#body' will do the trick.

删除目标:'#body'可以解决问题。

That particular line update the content of the body with the response.

该特定行使用响应更新正文的内容。

#1


0  

Removing target : '#body' will do the trick.

删除目标:'#body'可以解决问题。

That particular line update the content of the body with the response.

该特定行使用响应更新正文的内容。