Edited to make it easier to understand.
Ok,开发者_JAVA技巧 so the problem is that jQuery does not pass value to a certain PHP file in order to run a DELETE query and remove the content you requested to be removed from database.
The script works great with one other file which requests the information from MySQL and loads it via AJAX call to a php file.
The problem might be in this script the actual AJAX
$(".removeNote").live('click',function() {
$("#qpbox-content").show();
$("#qpbox-overlay").show();
$("#qpbox-loader").html("<img src='http://www.ajaxload.info/images/exemples/4.gif' />");
var xhr = $.ajax({
type: "GET",
url: "_class/delete_notes.php",
data: "ajax=1&nid=" + this.parentNode.id,
success: function(html){
$("#qpbox-utm").html(html);
$("#qpbox-loader").html("");
},
error: function (XMLHttpRequest, textStatus, errorThrown) {$("#qpbox-loader").html(errorThrown);}
});
});
this is the part from which the code above should get the value
<p style="margin-bottom:3px;" id="$nid">
<div id="$nid" style="float: right; padding: 4px;cursor: pointer;" class="removeNote">
<img src="$icon_sys_delete" alt="remove note" title="remove note"/>
</div>
</p>
the value is noted as $nid
and this is the actual delete part
<?php
include '../object/db.class.php';
if($_GET['ajax'] == '1') {
$nid = $_GET['nid'];
$query = mysql_query("DELETE FROM notes WHERE nid = '$nid'");
echo "Note removed!";
}
?>
So thats it...
Try changing
data: "ajax=1&nid=" + this.parentNode.id,
to
data: "ajax=1&nid=" + jQuery(this).closest('div').attr('id')
Ive assumed that the "div" is the one that you are looking for to get the "id" value.
The problem with your code snippet is you have mixed JQuery with raw javascript. If you wanted to do it your way(without using jquery to get the value), you could use
data: "ajax=1&nid=" + this[0].parentNode.id,
The issue is that <p>
does not contain <div>
. So, the parentNode
of .removeNote
is not the p
tag. Also, id
attribute is supposed to be unique. I would remove nid
from p
and simply use this.id
.
精彩评论