Heres an example of my js and action. Btw im using jquery.

// Js
function deleteAvatar(user_id) {
        $.ajax({
                type: "POST",
                url:  "/ajax/deleteAvatar/",
                data: "data[user_id]="+ user_id,
                success:

                function (response) {
                        // Do something with response
                }
        });

        return false;
}

// Action
function deleteAvatar() {
        $user_id = $this->Auth->user('id');
        $owner_id = $this->data['user_id'];

        if ($this->validRequest($owner_id) && $user_id == $owner_id) {
                if ($this->User->deleteAvatar($this->Auth->user())) {
                        $this->_refreshAuth('avatar', '');

                        echo 'pass';
                        return;
                }
        }

        echo 'fail';
        return;
}

The echos are my js response, and validRequest() is a custom method I
wrote.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to