weixin_33692284 2016-03-19 19:25 采纳率: 0%
浏览 2

在ajax中编辑后发出警报

I am implementing a simple insert and edit using ajax however on the edit it is not displaying the alert and while insertion it is telling undefined index despite my field names are as in my database

edit.php

<?php
    $connect=mysqli_connect("localhost","root","") or die('Could not connect: '.mysqli_error()); mysqli_select_db($connect,'elearning') or die ('database not found: '.mysqli_error()); 
    $id = $_POST["pageID"]; 
    $text = $_POST["text"]; 
    $column_name = $_POST["column_name"];
    $sql = "UPDATE page SET ".$column_name."='".$text."' WHERE pageID='".$id."'"; 
    if(mysqli_query($connect, $sql)) { echo 'Data Updated'; } 
?>

page.php

<script>
  $(document).ready(function() {
    function fetch_data() {
      $.ajax({
        url: "select.php",
        method: "POST",
        success: function(data) {
          $('#live_data').html(data);
        }
      });
    }
    fetch_data();
    $(document).on('click', '#btn_add', function() {
      var cid = $('#cid').text();
      var name = $('#name').text();
      var icon = $('#icon').text();
      var src = $('#src').text();
      var hint = $('#hint').text();
      var category = $('#category').text();

      $.ajax({
        url: "insert.php",
        method: "POST",
        data: {
          cid: cid,
          name: name,
          icon: icon,
          src: src,
          hint: hint,
          category: category
        },
        dataType: "text",
        success: function(data) {
          alert(data);
          fetch_data();
        }
      })
    });

    function edit_data(id, text, column_name) {
      $.ajax({
        url: "edit.php",
        method: "POST",
        data: {
          pageID: id,
          text: text,
          column_name: column_name
        },
        dataType: "text",
        success: function(data) {
          alert(data);
        }
      });
    }

    $(document).on('click', '.btn_delete', function() {
      var id = $(this).data("id7");
      if (confirm("Are you sure you want to delete this?")) {
        $.ajax({
          url: "delete.php",
          method: "POST",
          data: {
            pageID: id
          },
          dataType: "text",
          success: function(data) {
            alert(data);
            fetch_data();
          }
        });
      }
    });
  });
</script>

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
    • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序