php - Multi Delete using checkbox -


i learning cakephp , i've been trying delete multiple (checked) record using checkbox, still not success. here's jquery :

            var ids = [];   $(':checkbox:checked').each(function(index){    ids[index] = $(this).val();;    alert(ids[index]);    });    //alert(ids);   var formdata = $(this).parents('form').serialize();     $.ajax({          type: "post",          url: "tickets/multi_delete",          data:"id="+ids,          success: function() {      alert('record has been delete');     },     error:  function(xmlhttprequest, textstatus, errorthrown) {        alert(xmlhttprequest);        alert(textstatus);        alert(errorthrown);               }    }); 

and here code in controller :

function multi_delete() {   $delrec=$_get['id'];   //debuger::dump($del_rec);   foreach ($delrec $id) {     $sql="delete tickets id=".$id;     $this->ticket->query($sql);   };     } 

anybody me please. thank

you try .join(',') on array of ids , explode() on server side array of ids passed script.

e.g.

var idstr = ids.join(',');  

pass (idstr) ajax call

$.ajax({      type: "post",      url: "tickets/multi_delete",      data: {id:idstr},     //more code cont. 

on server side:

$ids = explode(',',$_post['ids']); 

or

check jquery.param() function in jquery docs. apply , ids array , pass $.ajax({});

note: using post , not http method in code provided


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -