MohamedB MohamedB - 9 months ago 42
Javascript Question

Using Ajax_Jquery to perform a delete action in Zend

I'm new to Ajax/jQuery.

I want to delete a row (email) in the database (emails table) when user presses a link in my view.

Here is my view example:

<a href="delete/id/<?= $email['id'] ?>" class="btn">
<i class="icon-trash icon-white"></i>

I have an action in my controller
that deletes entries, I want to call this action with some jQuery so that I don't need to go to delete view page.


create a delete action in your zend controller

public function deleteAction() {

$request = $this->getRequest();
$id= $request->getPost('id');
your code to delete the row from database using this id
when row deleted successfully then echo 'success' else echo 'failed'

now come to jquery ajax code

<script type="text/javascript">
function deleteRow(id) {
        var baseurl = '<?php echo baseUrl();?>';
        url: baseurl+"/delete/id/"+id,
        if(res== 'success'){
          alert("row deleted successfully");
       } else {
         alert("failed to delete row");

call the deleteRow function on your delete button and pass the id in it.