I have a problem with my jquery. I have a table with several records, and with each record there is a delete link. Clicking this link deletes a specific record. This is normal, but I try, when the record is deleted, it just disappears without refreshing the page. For this, I have jquery code that works fine on a separate page, but when I try to integrate it with my actual code, nothing happens at all. I replaced $ with jQuery, but nothing happens anyway. I also checked other reasons, but nothing worked. Can someone point out what might be missing, or I'm wrong. Codes below:
This is my line code that is inside the foreach, so multiple instances have been created
<tr class="showdel"> <td class="align"><input type="checkbox" name="instanceids[]" id="checkid" value="<?php echo $instanceid; ?>" /></td> <td class="align"><?php echo $i++.'.'; ?></td> <td><?php echo $title; ?></td> <td><a href="javascript:void(0);" class="delete" id="<?php echo $instanceid; ?>">Delete</a></td> </tr>
Below is my jquery code that deletes the record and it just disappears. It is located in the main section of the page.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript"> jQuery(function() { jQuery(".delete").click(function() { var element = jQuery(this); var del_id = element.attr("id"); var info = 'id=' + del_id; if(confirm("Are you sure you want to delete this?")) { jQuery.ajax({ type: "POST", url: "content_list.php", data: info, success: function() {} }); jQuery(this).parents(".showdel").animate({ backgroundColor: "#003" }, "slow") .animate({ opacity: "hide" }, "slow"); } return false; }); }); </script>
Please indicate what I am doing wrong. Thanks in advance.
PS: Here is my whole chapter. See if that helps. Possibly the wrong order of scripts.
<head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content=""> <meta name="author" content=""> <title><?php echo $client; ?> Admin</title> <link href="css/bootstrap.min.css" rel="stylesheet"> <link href="css/sb-admin.css" rel="stylesheet"> <link href="css/style.css" rel="stylesheet"> <link href="css/pagination.css" rel="stylesheet"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript"> jQuery(".delete").click(function() { var element = jQuery(this); var del_id = element.attr("id"); var info = 'id=' + del_id; if(confirm("Are you sure you want to delete this?")) { jQuery.ajax({ type: "POST", url: "content_list.php", data: info, success: function() {} }); jQuery(this).parents(".show").animate({ backgroundColor: "#003" }, "slow") .animate({ opacity: "hide" }, "slow"); } return false; }); </script> <script type="text/javascript" src="js/validate_category.js"></script> <script type="text/javascript" src="js/validate_subcategory.js"></script> <script type="text/javascript" src="js/validate_subsubcategory.js"></script> <script type="text/javascript" src="js/selectall.js"></script> <script type="text/javascript" src="js/validate_content.js"></script> <script type="text/javascript" src="js/validate_resource.js"></script> <script type="text/javascript" src="js/validate_data.js"></script> <script type="text/javascript" src="js/ajax_scripts.js"></script> </head>
Also my table is loaded by ajax call as below.