jquery Ajax Delete Detailed

Source: Internet
Author: User

The

 ajax is a local refresh. Using jquery will simplify a lot. The following is a detailed description, combined with a case of Ajax deletion, to

First look at the HTML interface code:   <a href= "javascript:;  onclick=" Delete_order (' <?php echo $item [order_id];?> ') " ><img src= "images/admin/delete-icon.png" border= "0"/></a> this one picture link, indicating deletion. It does not jump to an interface, but instead clicks off the Click event. The   Click event Executes the Delete_order () method. This method passes a parameter, the order number. With this parameter, you can perform the appropriate delete operation.   The following jquery code:   Code is as follows: <script>     function Delete_order (order_id) {        & nbsp   CONFIRM_ = confirm (' This action would delete current order! Are you sure? ');         if (confirm_) {            $.ajax ({        & nbsp       Type: "POST",                 URL: ' index.php/admin/order/del/' +order_id,                 Success:function (msg) {        &NBS P          //alert ("Test Order");                    //all Delete is Success,this can execute                     $ ("#tr_" +order_id). Remove ();                 (           });        }    ; </script>   Start a prompt box to confirm deletion?   If confirmed, perform AJAX operations.   in jquery, there is a $.ajax () method.   Here are three parameters, one is type, here is post,   the second is the address, this is the key, it is responsible for the data, transfer to the backend server to execute.   The third parameter is a callback function, and if the deletion succeeds, the action is performed. At this point, you can perform some actions, such as removing this deleted record. The combination is the following line of code. For no record, give a dynamic ID, which is used as the basis for deletion. Note here that the callback function will not be executed until all that must be done in the background is successful.   <TR id= "tr_<?php echo $item [' order_id '];?>" ></tr>   The following is the background code     code as follows: Function del () {    $order _id = $this->uri->segment (4);     if ($order _id > 0) {  &nbs P   $this->db->delete (' billing ', Array (' order_id ' => $order _id));       $this->db->delete (' shipping_address ', Array (' order_id ' => $order _id));       $this->db->delete (' order_products ', Array (' order_id ' => $order _id));       $this->db->delete (' comments ', array (' order_id ' => $order _id));    }     $this->db->delete ($this->tbname, array (' ID ' => $order _id));  }   A method in this background controller, the $this->uri->segment () method gets the parameter and assigns the parameter to the variable order_id.   You can then perform the appropriate delete operation in the background. If the deletion succeeds, there will be a default message passed to the success method.   The success method encountered today was unsuccessful because one of the deletion operations was unsuccessful and the hidden information was not passed to the success method. Why is it not successful? Because $this->db->delete (' shipping_address ', Array (' order_id ' => $order _id)) does not correspond to the name of the table in the database, it is probably modified by someone else. After the   was amended, the success method was successfully executed.     This is a simple example of Ajax. Can simply illustrate the role of Ajax. Do not need to refresh the interface, directly secretly to the background to operate, the successful operation, you can also perform the corresponding action, through jquery to complete

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.