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

前端 未结 2 476
被撕碎了的回忆
被撕碎了的回忆 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:33

    I am very late to the party! But a while back, about 3months ago I faced this problem. And what it turned out to be was that I was not giving permission to the user to access that action. The solution was to add some code in the AppController beforeFilter(), something like :

    function beforeFilter(){
        $this->Auth->allow('my_actions_name');
    }
    

    However I am not really sure why it re-renders the parent div, or sometimes the whole page, but my guess is, that cake is set so that whenever the action is not accessible/allowed, some routing takes place and perhaps index or other default actions, are executed, which causes that to be rendered within your ajax view.

    If you inspect the request response inside the browser's network tab( in chrome), it becomes very clear that the response returned is the same content that is being rendered. However, I am a complete newbie and the is answer is based on speculation.

    If anyone can give a better explanation(please teach us), I will be the first to upvote :)

    Till then, Happy coding

提交回复
热议问题