有语法错误但不知道在哪里

时间:2017-05-21 03:22:19

标签: php html mysql ajax

好吧,我有一个表生成器,带有mysql db的数据。

首先,代码:

  

PHP

while($result = mysqli_fetch_assoc($SQL)){
          $tbl->addCell("<p onBlur = 'editTable(" . $result['id_user'] . ", this, 'Name')' contentEditable = 'true'>" . $result['Name'] . "</p>");
          $tbl->addCell("<p onBlur = 'editTable(" . $result['id_user'] . ", this, 'Username')' contentEditable = 'true'>" . $result['Username'] . "</p>");
          $tbl->addCell("<p onBlur = 'editTable(" . $result['id_user'] . ", this, 'Email')' contentEditable = 'true'>" . $result['Email'] . "</p>");
          $tbl->addCell("<p onBlur = 'editTable(" . $result['id_user'] . ", this, 'Grade')' contentEditable = 'true'>" . $result['Grade'] . "</p>" );
          $tbl->addCell("<input type = 'button' class = 'Edit-TBB' value = 'Edit'>
          <input type = 'button' class = 'Delete-TBB' value = 'Delete'>");
          $tbl->addRow();
      }
  

AJAX

function editTable(id, new_text, column) {
          $.ajax({
              url: "../PHP/Configuracion/edit_grade.php",
              type: "POST",
              data: 'id='+id+'&text='+new_text.innerText,
              success: function(data){
                  alert(column);
              }
          });
      }

以下是问题:

我有'editTable(" . $result['id_user'] . ", this, 'Name')'

In Chrome, it show me this

如果我更改Chrome中的代码,例如this ...这样可行,但我不知道我需要在代码编辑器中更改内容。

我需要改变什么?

谢谢!

1 个答案:

答案 0 :(得分:0)

您必须对onBlur值使用双引号,因为您使用单引号将js字符串表示为参数。要做到这一点,你需要在你的PHP中转义双引号。因此,将addCell调用更改为:

addCell("<p onBlur=\"editTable(" . $result['id_user'] . ", this, 'Name')\" contentEditable = 'true'>");
相关问题