CakePHP 2 component and ajax calls

Working with the secuity component on my ajax calls is not going the way they should.

How do you handle this in cakephp 2.x?

Appcontroller.php

public function beforeFilter() {
        $this->Security->blackHoleCallback = 'blackhole';
        if ($this->request->is('ajax')) {
            $this->Security->validatePost = false;
        }

It doesn't seem to work ...

+5
source share
1 answer

ajax, , Cake. , ajax. , Javascript, ajax, . , CSRF ( - ), CSRF ( $this->request->params['_Token']['key']).

:

<?php
    echo $this->Form->create('AjaxForm');
        echo $this->Form->hidden('value');
    echo $this->Form->end();
?>

<script>    
    function makeAjaxCall()  {
        $.post(
            ajaxUrl,
            $('#AjaxForm').serialize(),
            function(data) {
                $('#AjaxForm [name="data[_Token][key]"]').val(data.newCsrfToken)
            }
        );
    };
</script>

, , , ajax. https://github.com/QTSdev/DynamicSecurity.

+3

All Articles