2014-10-27 09:28
浏览 46

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

I am new to cakePHP, I have submit button in cakePHP

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

I would like to add one javascript validation, if the validation returns true then it should proceed for submission otherwise submission should be terminated.

The whole submission is calling through ajax and I was advised to use $ajax to implement.

my javascript function:

var firstCompare = new Array();
fucntion myValidation(){    
var otherCompare = new Array();
result = (otherCompare.length === _.intersection(otherCompare, firstCompare).length); 
firstCompare = otherCompare;
return result;

Please help me.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dragonpeng200811111 2014-10-27 09:36

    use the for id and check on submit or click event of your button.

    $(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
    点赞 打赏 评论

相关推荐 更多相似问题