How to use Js->submit() in CakePHP?

前端 未结 2 515
被撕碎了的回忆
被撕碎了的回忆 2021-01-14 03:11

Im trying to create a simple Ajax form for a message board in a CakePHP application, but I can\'t for the life of me figure out how to properly use the Js->submit() function

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-14 03:28

    What happens is that it loads the default layout. You'll have to change the layout to ajax with the following line:

    $this->layout = 'ajax';
    

    You insert that line inside your isAjax() condition.

    Also your options array has the wrong format. The action key should be inside the url key.

    $this->Js->submit('Post Your Message', array(
            'url' => array(
                'action' => 'add'
            ),
            'update' => '#message_board'
        )
    );
    

提交回复
热议问题