Php+ajax implementation of all-Select Delete method

Source: Internet
Author: User
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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.