Saturday, April 4, 2009

Re: AuthComponent and AJAX Requests to another Controller

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: