我在AJAX中错过了什么?

时间:2015-02-23 06:38:45

标签: php ajax database

我想使用ajax删除图片,但我不知道我的按钮出错的地方。

这是我带照片的第一页。



<html>
    <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">               </script>
        <script>
            $(document).ready(function () {
                $("#button").click(removecat);
            });

            function removecat() {
                $("#resultDIV").load("removecat.php");
            }
        </script>
    </head>
    <body>
    <div class="container">

    <?php
    require 'dbfunction.php';
    require 'DBCategory.php';

    $con = getDbConnect();
    $categoryArr = getcategoryArrCon($con, "STATUS_ACTIVE");


    foreach ($categoryArr as $Name => $InfoArr) {
    ?>

    <div class="col-md-3">
    <div class="title">
       <h3><?php echo $Name; ?></h3>
    </div>
    <img src="<?php echo "img/" . $InfoArr['image'] ?>" class="img-rounded" width="250" height="220">
    <a class="btn btn-danger"  id="button" value="Delete" name="delete">Delete</a>
    <br /><br />
    <div id="resultDIV">
    </div>
    </div>               
    <?php } ?>
    </div>

    </body>
&#13;
&#13;
&#13;

这是我的removecat.php页面,

&#13;
&#13;
<?php
  require 'dbfunction.php';
  $con = getDbConnect();

  if (mysqli_connect_errno($con)) {
     echo "Failed to connect to MySQL: " . mysqli_connect_error();
  } else {
     mysqli_query($con, "UPDATE category SET status = 1 WHERE categoryid = '$Name'"); //$name from Firstpage

    if (mysqli_affected_rows($con) > 0) {
        echo "You have successfully remove $Name."; //$name from Firstpage
    } else {
        echo "NO changes were made.";
    }
  mysqli_close($con);
  }
 ?>
&#13;
&#13;
&#13;

我不太确定如何将$ name从第一页引导到removecat.php页面。有人可以帮忙吗?

0 个答案:

没有答案