Last active
August 29, 2015 14:06
-
-
Save taleeb35/e61f58af9944511b1669 to your computer and use it in GitHub Desktop.
Delete with Jquery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function delete($id = null) { | |
if($this->request->is('ajax')) { | |
//$this->autoRender = false; | |
if ($this->User->delete($id)) { | |
$response = $this->Session->setFlash(__('User deleted')); | |
$response .= $this->redirect(array('action' => 'index')); | |
} else { | |
$response = $this->Session->setFlash(__('User was not deleted')); | |
$response.= $this->redirect(array('action' => 'index')); | |
} | |
return json_encode($response); | |
} | |
} | |
$(document).ready(function() { | |
$('a.delete').click(function(e) { | |
var __this = this; | |
e.preventDefault(); | |
var parent = $(this).parent("td").parent("tr"); | |
$.ajax({ | |
type: 'get', | |
url: $(__this).attr("href"), | |
beforeSend: function() { | |
parent.animate({'backgroundColor':'#fb6c6c'},3000); | |
}, | |
success: function(response) { | |
if(response.success){ | |
parent.slideUp(300,function() { | |
parent.remove(); | |
}); | |
}else{ | |
alert("Failed to delete message"); | |
parent.animate({'backgroundColor':'#fff'},1000);//Restore your background back | |
} | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
View\YourName\delete.ctp