duanba8173 2019-03-10 08:15
浏览 287

ajax Uncaught ReferenceError:post未在HTMLButtonElement中定义。<anonymous>

Have no idea what it could be. Please help me release this ajax commentaries. I have never done this before. HTML form for input text and some ids:

 <form id="send_comment" method="POST" action="write_comment.php">
                        <input hidden type="text" id="c_post_id" name="c_post_id" value="<?=$_GET["id"]?>">
                        <input hidden type="text" id="c_user_id" name="c_user_id" value="<?=$user_id?>">
                        <div class="form-group shadow-textarea">
                          <textarea class="form-control z-depth-1" type="text" id="c_text" rows="3" placeholder="Write comment here..." name="c_text" required pattern="^[a-zA-Z0-9\s]+$"></textarea>
                        </div>
                      <div class="col-md-12 text-center">
                          <button id="make_comment" class="btn btn-default" name="make_comment" type="submit" value="Submit"><i class="fas fa-check" style="font-size: 35px;"></i></button>
                      </div>
                    </form>

PHP processing:

if($_POST["make_comment"]) {
       $c_post_id = $_POST["c_post_id"];
       $c_user_id = $_POST["c_user_id"];
       $c_text = $_POST["c_text"];
       $date = date("m/d/y G:i:s<br>", time());

       $sql = "INSERT INTO `comments` VALUES ('$c_post_id','$c_user_id',null,'$c_text','$date')";
          if ($connect->query($sql) === TRUE) {
              header("Location: http://thecobnmod.com/post.php?id=$c_post_id");
          }
          else {
              exit( "Error: " . $sql . "<br>" . $conn->error);

          }
    }

JS ajax:

function funcSuccess (data) {
        $("#comment_ajax").text(data);
    }
    function funcBefore (){
        $("#comment_ajax").text("Loading comment...");
    }
    $(document).ready(function(){
        $("#make_comment").bind("click", function () {
            event.preventDefault();
            $.ajax({
            post: $("#c_post_id").val(),
            user: $("#c_user_id").val(),
            text: $("#c_text").val(),
            url: "write_comment.php",
            type: "POST",
            data: {
                c_post_id:post, 
                c_user_id:user, 
                c_text:text
            },
            dataType: "html",
            beforeSend: funcBefore,
            success: funcSuccess
            });
        });
    });

Post id comes fro GET request to input field. I thought it could be a problem but not. now I really do not know what's wrong. Please help.

  • 写回答

1条回答 默认 最新

  • dornc9470 2019-03-10 08:23
    关注

    I strongly recommend consulting the documentations: Ajax doc

    Ajax doesn't have post property AFAIK! I'm not sure what you wanted to do, but here is a simple ajax example:

    $.ajax({
        url: 'here/is/some/url',
        type: 'post',
        data: {
                 some_key: 'value1',
                 other_key: 'value2',
                 /*...*/
              },
    
        dataType: 'html',
        beforeSend: function() {/*...*/}
        success: function(result) {/*...*/},
        error: function(error) {/*...*/}
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题