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

标签 php jquery ajax intel-xdk

我想在 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>

//删除销售.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 -->

关于php - 在XDK中使用ajax和php删除sql中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32982261/

相关文章:

PHP 脚本从 POST 返回 responseText 到 AJAX?想要使用 Ajax POST 返回消息

PhpUnit 当我使用 Mock Builder for Interface 时,我得到了正确的类

php - 如何在 Edit.php 页面上编辑后更新 Index.php 页面上的数据库值

php - 如何在 symfony2 功能测试中测试表单事件和事件监听器?

jquery-ui datepicker 多种语言

jquery - 使用 jQuery 清除搜索框中的默认值

jquery - Jqplot 线图,具有悬停在线效果

php - 如何通过 php 连接到 ftps 服务器?

javascript - 数据表操作按钮未被禁用

java - DWR 对 JavaScript 变量的响应