weixin_33726318 2013-06-05 08:57 采纳率: 0%
浏览 80

为什么使用jQuery更新文本框后数据库不会自动更新?

我正在创建一个文本框,该文本在用户键入后无需提交便会自动更新为mysql,现在的问题是该文本框不会更新数据库 这是我参考以下所有观点进行编辑的结果,虽然仍然存在一些问题,但是总比没有显示好。

这是文本框输入:

  echo "<td class=\"align-center\"><input type=\"text\" name=\"comment\" id=\"comment\" onKeyPress=\"getComment($id,this)\" /></td>";

我的JavaScript:

function getComment(id, txt_box)
{
var value = txt_box.value;

    $.ajax({
        'url': 'updatecomment.php',
        'data': {"id": id, "comment": value},
        'success': function (response) {
            console.log(response);
            //TODO: use server response
        }
    });
}

最后是updatecomment.php:

 <?php require_once("../includes/connection.php") ?>
 <?php require_once("../includes/functions.php") ?>

 <?php
     $id =$_GET['id'];
     $comment = $_GET['comment'];


     $query = "UPDATE tblinternapplication SET comment = '".mysql_real_escape_string($comment) ."' WHERE id = $id";
     $result = mysql_query($query, $connection);
 ?>
  • 写回答

5条回答 默认 最新

  • weixin_33691700 2013-06-05 08:58
    关注
    echo "<td class=\"align-center\"><input type=\"text\" name=\"comment\" id=\"comment\" onPressKey=\"getComment($id,this.id)\" required/></td>";
    

    should be

    echo "<td class=\"align-center\"><input type=\"text\" name=\"comment\" id=\"comment\" onkeypress=\"getComment($id,this.id)\" required/></td>";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?