dongzen7263 2014-01-14 05:47
浏览 25

ajax文件中的mysql查询未执行。 努力处理错误报告

I have a problem with Ajax. I've pasted my code below.

I have some jquery that listens for a click and then fires the ajax, but my ajax isn't working. The Javascript works fine, because the currentTODO.fadeOut('fast'); piece of code after I call the ajax works.

I'm not sure if the problem lies in the MySQL query, and I am also struggling with checking and reporting on any errors that come from my ajax.php file.

I must add that I am quite new to ajax, and I copied the original code from here: http://tutorialzine.com/2010/03/ajax-todo-list-jquery-php-mysql-css/

But I had to make so many changes to the code to get it to work correctly in my environment and fulfill my needs.

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');
    });

code in 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";
?>

Your help will be greatly appreciated. Please let me know if you require any additional information from me.

  • 写回答

1条回答 默认 最新

  • doudang1890 2014-01-14 05:53
    关注

    Try this,

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

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?