i have added helpers and component of "request handler" in controller.
i have created a view with delete link as bellow
<?php foreach ($users as $user): ?>
<tr>
<td><?php echo $user['User']['id']; ?></td>
<td><?php echo $this->Html->link($user['User']['name'],
array('action'=>'view', $user['User']['id'])) ?></td>
<td><?php echo $user['User']['contact']; ?></td>
<td><?php echo $html->link('Delete',array('action'=>'delete',
$user['User']['id']),array('class'=>'confirm_delete'));?>/
<?php echo $this->Html->link('Edit', array('action' => 'edit',
$user['User']['id']));?>
</td>
</tr>
<?php endforeach; ?>
my controller contain DELETE action as bellow
//to delete user
function admin_delete($id=null) {
// set default class & message for setFlash
$class = 'flash_bad';
$msg = 'Invalid List Id';
// check id is valid
if($id!=null && is_numeric($id)) {
// get the Item
$item = $this->User->read(null,$id);
//print_r($item);
// check Item is valid
if(!empty($item)) {
// try deleting the item
if($this->User->delete($id)) {
$class = 'flash_good';
$msg = 'one user has been deleted
successfully!';
} else {
$msg = 'There was a problem deleting your Item,
please try again';
}
}
}
// output JSON on AJAX request
if($this->RequestHandler->isAjax()) {
$this->autoRender = $this->layout = false;
echo json_encode(array('success'=>($class=='flash_bad') ? FALSE
:
TRUE,'msg'=>"<p id='flashMessage' class='{$class}'>{$msg}</p>"));
$this->autoRender = false;
}
// set flash message & redirect
$this->Session->setFlash($msg,'default',array('class'=>$class));
$this->redirect(array('action'=>'user'));
}
i have added required .js files in Js folder of webroot.
but when i click on delete, it deletes the record without alert msg
box.
it deletes the data without confirmation.
give the solution on it.
thank u.
On Jan 24, 11:43 am, Ryan Schmidt <[email protected]> wrote:
> On Jan 24, 2011, at 00:39, andy_the ultimate baker wrote:
>
> > i am trying to delete item using ajax,
>
> Ok, what have you tried so far?
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php