在XDK中使用Ajax和php删除sql中的数据

我想在xdk中按下删除按钮时删除sql中的一行数据.我搜索了一些代码,但仍然没有删除数据.

这是PHP文件(delete.PHP)

<?PHP
include('dbcon.PHP');

$foodid = $_POST['foodid'];

$query = "DELETE FROM menu WHERE id ='$foodid'";
$result=MysqL_query($query);

if(isset($result)) {
echo "YES";
} else {
echo "NO";
}
?>

在这是我的ajax代码.

$("#btn_delete").click( function(){
alert("1");

    var del_id = $(this).attr('foodid');
    var $ele = $(this).parent().parent();

alert("2");

    $.ajax({
        type: 'POST',
        url: 'http://localhost/PHP/delete.PHP',
        data: { 'del_id':del_id },
        dataType: 'json',
        succes: function(data){
alert("3");
            if(data=="YES"){
                $ele.fadeOut().remove();
            } else {
                alert("Cant delete row");
            }
        }
    });
});

如您所见,当我在xdk中运行程序时,我放置了警报以了解我的代码是否正在处理.它最多只警报到alert(“ 2”); .而不是继续到3.所以我认为我的Ajax在这里错误的部分.我对ajax有点陌生.

解决方法:

                            <?PHP
                                $sqli= "*select * from temp_salesorder *";
                                $executequery= MysqLi_query($db,$sqli);
                                while($row = MysqLi_fetch_array($executequery,MysqLI_ASSOC))
                                {       
                            ?>                  

 //"class= delbutton" is use to delete data through ajax

<a href="#" **id =<?PHP echo $row['transaction_id']; ?>** class="**delbutton**" title="Click To Delete"><button> Cancel</button></a>





     <!-- language: lang-js -->

     //Ajax Code
        <script type="text/javascript">
        $(function() {


        $(".delbutton").click(function(){

        //Save the link in a variable called element
        var element = $(this);

        //Find the id of the link that was clicked
        var del_id = element.attr("id");

        //Built a url to send
        var info = 'id=' + del_id;

         $.ajax({
           type: "GET",
           url: "deletesales.PHP",
           data: info,
           success: function(){

           }
         });
                 $(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
                .animate({ opacity: "hide" }, "slow");



        return false;

        });

        });
        </script>

//deletesales.PHP

<?PHP
$db_host        = 'localhost';
$db_user        = 'root';
$db_pass        = '';
$db_database    = 'pos'; 
$db = MysqLi_connect($db_host,$db_user,$db_pass,$db_database);
    $id=$_GET['id'];  <!-- This id is get from delete button -->


    $result = "DELETE FROM temp_salesorder WHERE transaction_id= '$id'";
     MysqLi_query($db,$result);

?>



    <!-- end snippet -->

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...