Monday, September 28, 2009

Ajax (jquery) Question - am I doing this right?

Hey,

i try to do my first steps with ajax (jquery) - In a list, i would
like to have a switch which changes the 'active' paramter in the db
for this entry.

As i understand this topic, I need to do an ajax call to a controller
method, which do the changes, and the realod the div with the new
entries...

so this is my controller method:

function admin_switchStatus($id) {
$this->News->id = $id;
$news = $this->News->read('active', $id);

switch($news['News']['active']) {
case "1":
$this->News->saveField('active', 0);
break;
case "0":
$this->News->saveField('active', 1);
break;
}

$this->redirect(array('controller'=>'news', 'action'=>'index',
'admin'=>true));
}


the jQuery for this in the admin index view is:

$('.switchStatus').click(function(){
$.get($(this).attr('href'), function(data){
$('#mainContent').html(data);
});
return false;
});

Is this the correct (?) way to achieve this?

Basically it works - but cake reloads not the admin_index but the
index view...


--~--~---------~--~----~------------~-------~--~----~
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: