ajax文件中的mysql查询未执行.在错误报告方面举步维艰



我对Ajax有问题。我已经在下面粘贴了我的代码。

我有一些jquery,它会监听点击,然后启动ajax,但我的ajax不起作用。Javascript工作得很好,因为在我调用ajax之后的currentTODO.fadeOut('fast');段代码可以工作。

我不确定问题是否出在MySQL查询中,我也在努力检查和报告来自我的ajax.php文件的任何错误。

我必须补充一点,我是ajax的新手,我从这里复制了原始代码:http://tutorialzine.com/2010/03/ajax-todo-list-jquery-php-mysql-css/

但我不得不对代码进行很多更改,以使其在我的环境中正确工作并满足我的需求。

Javascript:

$("#dialog-confirm").dialog({
resizable: false,
height:130,
modal: true,
autoOpen:false,
buttons: {
'Delete item': function() {
$.get("ajax.php",{"action":"delete","id":currentTODO.data('id')},function(msg){
currentTODO.fadeOut('fast');
})
$(this).dialog('close');
},
Cancel: function() {
$(this).dialog('close');
}
}
});
$('.todo a.delete').on('click',function(){
$("#dialog-confirm").dialog('open');
});

ajax.php 中的代码

<?php
class ToDo{
public static function delete($id){
mysql_query("UPDATE Todo SET StatusID = 6 WHERE TodoID=".$id);
if(mysql_affected_rows($GLOBALS['link'])!=1)
throw new Exception("Couldn't delete item!");
}
}
$id = (int)$_GET['id'];
try{
switch($_GET['action'])
{
case 'delete':
ToDo::delete($id);
break;
}
}
catch(Exception $e){
echo $e->getMessage();
die("0");
}
echo "1";
?>

我们将非常感谢你的帮助。如果你需要我提供任何额外的信息,请告诉我。

试试这个,

$.get("ajax.php",{action:"delete",id:currentTODO.data('id')},function(msg){
//____________^______________^___________________________
currentTODO.fadeOut('fast');
})

最新更新