ajax调用后清空序列化表单

时间:2013-10-14 17:53:20

标签: jquery spring-webflow-2

我正在使用spring webflow,我在浏览视图状态页面时出现问题。在ajax调用之后,我总是得到 $('#form')。serialize()=“”。 我有下一个ajax电话:

var bindContinueButton = function () {
    $('#continueBtn').bind('click', function () {
        var url = $('#form').attr('action') + setFlowEvent('continue');
        $.ajax({
            type : "POST",
            url : url,
            cache:false,
            data: $('#form').serialize(),
            dataType: "text",
            success : function(response) {
                var newContent = $('#ajax-content', response).html();
                $('#ajax-content').html(newContent);
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert("error!");
            }
        });
    });
};

我有下一个jsp剪切渲染:

<div id="ajax-content">
    <jsp:include page="../../jsp/common/head.jsp"/>
<table class="t1">
    <tbody>
    <portlet:actionURL var="actionURL" portletMode="view">
        <portlet:param name="execution" value="${flowExecutionKey}"/>
    </portlet:actionURL>

    <form:form id="form" modelAttribute="model" action="${actionURL}" method="post">
        <jsp:include page="../../jsp/creation/popup-save-as.jsp"/>
        <jsp:include page="../../jsp/creation/documentNumber.jsp"/>
        <jsp:include page="../../jsp/creation/initialAmount.jsp"/>
        <jsp:include page="../../jsp/creation/currentAccount.jsp"/>
        <jsp:include page="../../jsp/creation/addRegularPayment.jsp"/>
        <jsp:include page="../../jsp/creation/regularPaymentFields.jsp"/>
        <jsp:include page="../../jsp/creation/otherConditions.jsp"/>
        <jsp:include page="../../jsp/creation/certification.jsp"/>
    </form:form>

    <%-- BUTTONS --%>
    <jsp:include page="../../jsp/creation/actionButtons.jsp"/>
    </tbody>
</table>
</div>

因此,当我提交表单时,我自动运行我的服务器验证程序而不是转到ajax回调成功函数 $('#ajax-content')之后.html(newContent)我得到 $('#form')。serialize()。请帮我解决这个问题。谢谢

2 个答案:

答案 0 :(得分:0)

在成功回调中替换您的内容后,您需要重新绑定:

 $('#continueBtn').bind('click', function(){...});

答案 1 :(得分:-1)

我们需要只获取输入值,而ajax提交正确???

所以你可以像这样使用: $('input').serialize()。