douyi2798 2014-03-22 19:46
浏览 22
已采纳

Jquery AJAX失败了

I am trying to send an ID to a PHP page to update a database. First time using AJAX.

I keep getting an error. The PHP file is in the same directory

function approve(id) {

        $.smallBox({
            title : "Are you sure you would like to approve this indicator?",
            content : "<p class='text-align-right'><a href='javascript:approve_indicator(" + id + ");' class='btn btn-primary btn-sm'>Yes</a> <a href='javascript:void(0);' class='btn btn-danger btn-sm'>No</a></p>",
            color : "#296191",
            //timeout: 8000,
            icon : "fa fa-bell swing animated"
        });


}

function approve_indicator(id){
        $.ajax({
              url: '/approve_indicator.php',
              type: 'post',
              data: 'id='+id,
              success: function() 
              {
                  alert('success, server says '+output);

                  location.reload();

              }, error: function()
              {
                  alert('something went wrong, rating failed');
              }
        });

}

this is the PHP. Not sure if it matters

$id = $_POST['id'];
$update_indicator = $con->preapre("UPDATE indicators SET approved = ? WHERE indicator_id = ?");
$update_indicator->execute(array(1,$id));
  • 写回答

1条回答 默认 最新

  • dsfdsf46465 2014-03-22 19:49
    关注

    Your PHP code contains preapre instead of prepare. This is likely giving you unwanted results. Also, using a web tool such as Firebug lets you see the AJAX responses. If your PHP errors are displayed, the response will tell you what is wrong with your PHP code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?