This article mainly introduces the method of Php+ajax implementation of all-select Delete, combined with the example form analysis of the HTML+JS front desk select and through the Ajax and background PHP Interactive implementation of bulk deletion of the specific procedures and related skills, the need for friends can refer to the next
Specific as follows:
<input type= "checkbox" id= "Ckb_selectall" onclick= "SelectAll ()" title= "Check/uncheck" ><a href= "javascript:void (0 ); "onclick=" Del_ () "title=" Delete selected data "style=" font-weight:normal "> Delete </a>
↑ Full Select checkbox
<input type= "checkbox" class= "ckb" id= "+con.id+" value= "+con.id+" >
↑ for delete items, the same name class is ckb, convenient operation, while the ID value is cleverly placed in input, easy to access.
function SelectAll () { if ($ (' #ckb_selectAll '). Is (': Checked ')) { $ (". ckb"). attr ("Checked", true);//Select All } else { $ (". ckb"). attr ("checked", false);//Cancel All }}
↑ Check Events
function Del_ () { var ids = '; $ (". ckb"). each (function () {if ($ () (') ' (') ' (') ' ( ': Checked ') ' { ids + = ', ' + $ (this). Val ();//Get ID } }); ids = ids.substring (1); To process the ID, remove the first comma if (ids.length = = 0) { alert (' Select option to delete '), } else { if (Confirm ("OK delete? It will not be recoverable after deletion. ") { URL =" action=del_call_record&ids= "+ IDs; $.ajax ({ type: "Post", URL: "send.php", Data:url, success:function (JSON) { if (parseint ( Json.counts) > 0) { alert (json.des); Location.reload (); } else { alert (json.des); } }, error:function (XMLHttpRequest, textstatus) { alert ("Page request error, Please check the retry or contact the administrator! \ n "+ Textstatus);}} );} }
↑ Delete with Ajax to handle.
↓ Background operation database, processing delete action.
$ids = Trim ($_request[' IDs '); $del _sql = "DELETE from Vicidial_call_record WHERE ID in (". $ids. ")"; /print_r ($del _sql); Exit;if (Mysqli_query ($db _conn, $del _sql)) { $counts = "1"; $des = "Success";} else { $counts = "0"; $des = "Failed";} $json _data = "{"; $json _data. = "\" counts\ ":". Json_encode ($counts). ","; $json _data. = "\" des\ ":". Json_encode ($des). ""; $json _data. = "}"; echo $json _data;break;
Complete
The above is the whole content of this article, I hope that everyone's study has helped.