开发者

$ajax->submit Does Not Go To Controller

开发者 https://www.devze.com 2023-01-26 04:31 出处:网络
I am using cakephp and pippoacl plugin and I simply cannot add a new role. What I modify in the plugin is to make the submit using ajax, something like this in my view (add开发者_开发知识库.ctp):

I am using cakephp and pippoacl plugin and I simply cannot add a new role. What I modify in the plugin is to make the submit using ajax, something like this in my view (add开发者_开发知识库.ctp):

<?php echo $ajax->submit(
        'submit',
        array(
            'url'   => array('controller' => 'roles', 'action' => 'add'),
            'before' => 'beforeSubmitAdd();',
            'complete' => 'completeSubmitAdd(request);'
        )
    );
?>

When the add.ctp gets loaded for the first time, I can print_r something from the controller. But the ajax submit above only executes the javascript on 'before' and 'complete'. I check on the firebug, the response is blank.

On my controller:

function add() {        
    print_r("start");
    if (!empty($this->data)) {  
        print_r("add new role");        

        // save new role
    }       
}

I use ajax submit for user and I don't have any problem adding new user. Is there any idea where I should check? I have been comparing the user and role code for a week and I have asked a friend to look at my code, too, but we still cannot find what causes this.

Thanks in advance! :D


I am not so familiar with the Ajax helper, but I haven't using it from so long that I can't remember what is it doing :).

Back to the problem. Did you check if the requested URL in the Ajax address is correct? This should work straightforward, but it's possible that the url to be invalid.

Are you using Security component (even just adding it on the var $components variable)?. This could lead to blank screen especially if you modifying the fields in the form somehow. Try to remove it and see if it's working without.

Finally I would say how I would do it with jQuery.

Following code should do the job:

$(document).ready(function(){
   $('form').live('submit', function(){ //handles also dynamically loaded forms
       var form = $(this).addClass('loading'); //indicate somehow that the form has been submitted
       $('#content').load($(this).attr('action'), $(this).serialize(), function(){
          form.removeClass('loading');
       });
   })
});

This will handle all submits in the forms of the system, but you can modify of course.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号