Confirm the dialog box to prevent Ajax operations, Ajax do Bulk Delete

Source: Internet
Author: User

In the bulk delete, you need to use confirm pop up a prompt box to let the user confirm whether to delete, click ok, Perform the action, click cancel, Cancel the Operation. however, If you use Ajax to upload the primary key value of the selected item to the processing page, if you use the following method to write confirm directly inside the button, after clicking cancel, Ajax will continue to do the operation, delete the selected Item.

1.confirm Error Notation:

<type= "button"  onclick= "return confirm (' OK to delete the selected item! ') "  ID=" piliang "  classbtn-primary btn-lg '  data-target = ' #myModal ' > Bulk Delete </button>

2. The following method can be used to write confirm in js, you can avoid this Problem.

(1) Button Code

<type= "button"  id= "piliang"  class   Btn-primary btn-lg '  data-target= ' #myModal '> Bulk Delete </button  >

(2) JS Code

$ ("#piliang"). Click (function(){        varStatu = Confirm ("confirm The deletion of the selected Items!") ");//write confirm in JS and pop up a message on the Page.         if(!statu)//If the click is Cancel        {            return false;//Back to Page        }        Else{//If you click ok, proceed to the following steps:            varattr =NewArray ();//Create an array$ (". qx"). each (function() {//Each loop iterates through all the check boxes               if($( this). prop ("checked"))//determine if The. ck is being Cycled.{attr.push ($ ( this). attr ("value"));//the property of the value is taken to the primary key value of the item data and thrown into the array attr .               }            }); varStra = Attr.join ("', '");//the lie[0 in the attr array] is split with ', '$.ajax ({url:".. /chuli/deletepiliang.php ", data:{stra:stra},//after splitting the array to the processing page, the format of the data is the primary key 1 ', ' primary key 2 ', ' primary key 3 here seems to be less than the outermost 2 ', with this question to see the processing pageType: "POST", DataType:"TEXT", Success:function(data) {window.location.href= "guanliry.php";            }                }); }        })

3. Handling Page deletepiliang.php

<? PHP Session_Start (); include (".. /libs/dbda.php "); $db New Dbda (); $attr = ($_post["stra"]); // the selected primary key value passed in . $sql = "delete from Jx_user where uid in (' {$attr} ')"; // Put the missing outermost "string here, (' {$attr} ') in {$attr} is the string to fetch, the outside of the" just make up for the missing ".  $db->query ($sql, 0);? >

Confirm dialog box cancels Ajax operations, Ajax does bulk deletion

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.