日期:2014-05-17  浏览次数:20623 次

Jquery ajaxSubmit的问题
使用 ajaxSubmit进行表单提交的时候,提交前进行了简单验证,然后提交,(假设故意让改验证不通过,即让username为空),结果提示“Username is required!”出现了N多次,不知道为什么,这感觉就是重复重复重复。。。提交啊,怎么会这样

代码:
HTML code


function showRequest(formData, jqForm, options)
{
    var queryString = $.param(formData);

    var thisForm = jqForm[0];
    var loginName = thisForm.username.value;
    if (loginName == '')
    {
    alert("Username is required!");
            
    return false;
     }
     return true;
}

function submitForm(thisForm)
{
    var options = {
        target:            '#loginForm',
        beforeSubmit:    showRequest,
        success:        showResponse,
        error:            showError,
        
        url:               'login.ns.module/loginAction.action',
        type:            'post',
        dataType:        'html',
        clearForm:        true,
        resetForm:        true,
        
        timeout:        3000
    };
    
    $(thisForm).submit(function()
    {
        $(thisForm).ajaxSubmit(options);
        
        return false;
    });
}

//-->
</script>
</head>
<body>
    <form name="loginForm" method="get" onsubmit="return submitForm(this);">
        <p><label accesskey=u>用户:<input type="text" name=username width="115px" maxlength="18"></label></p>
        <p><label accesskey=p>密码:<input type="password" name=password width="115px" maxlength="18"></label></p>
        <p><input type="submit" name="submitButton" value="登陆"/></p>
    </form>
</body>
</html>




------解决方案--------------------
Java code
$(thisForm).submit(function()
    {
        $(thisForm).ajaxSubmit(options);
        
        return false;
    });

------解决方案--------------------
探讨

Java code
$(thisForm).submit(function()
{
$(thisForm).ajaxSubmit(options);

return false;
});

变成
Java code

$(thisForm).ajaxSubmit(options);

……