CakePHP $ ajax->在客户端验证后提交提交

时间:2014-10-27 09:28:56

标签: javascript php jquery ajax cakephp

我是cakePHP的新手,我在cakePHP中提交了按钮

$ajax->submit( 'Submit', array( "update" => "gridbox_script", "url" => '/flots/comparaison_gridbox_update', "div"=>"button_submit", "loading" => "setIboxOpacity = setOpacity;showBG();showIndicator();" , "complete" => "hideBG();hideIndicator()" ) );

我想添加一个javascript验证,如果验证返回true,那么它应该继续提交,否则提交应该终止。

整个提交是通过ajax调用的,我被建议使用$ajax来实现。

我的javascript函数:

var firstCompare = new Array();
fucntion myValidation(){    
var otherCompare = new Array();
if(document.getElementById("file1").checked)
otherCompare.push('file1');
result = (otherCompare.length === _.intersection(otherCompare, firstCompare).length); 
firstCompare = otherCompare;
return result;
}

请帮帮我。

1 个答案:

答案 0 :(得分:0)

使用for id并检查提交或点击按钮事件。

$(document).ready(function() {
    $('#formId').on('submit', function() {
        var val = your_function()  //call the function and store the return value
        if (val) {
           //do the submission
        } else {
          //code in case of false
        }
    });
});