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 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置