2016-01-25 58 views
0

每当我按输入键它似乎并没有发布它只是去到下一行。我试过它与alert选项它确实工作,但是当我发布它不。AJAX请求输入密钥在textarea没有按预期工作

$(document).ready(function(){ 
    $('.comment').keydown(function (e){ 
     if (e.keyCode == 13) { 
      var post_id = $(this).attr('post_id'); 
      var comment = $(this).val(); 
      $.post('/comment.php', { post_id: post_id, comment: comment }); 
     } 
    }); 
}); 

的index.php:

<div class='comment_type_area'> 
    <textarea class='comment' post_id='<?php $shared_id2; ?>' id='text_comment' placeholder='Write a Comment'></textarea> 
    <button id='post_button' type='button'>Post</button> 

comment.php

include 'sqlconnect.php'; 
$post_id = $_POST['post_id']; 
$comment = $_POST['comment']; 
mysql_query("INSERT INTO `comment_system` 
(`id`, `user_id`, `post_id`, `first_name`, `date_time`, `comment`) 
VALUES (NULL, '1', '$post_id', '', '', '$comment')"); 

我怎样才能使按钮并回车键后财产以后?我似乎无法弄清楚。请帮忙。

+3

从你描述的问题奠定了与AJAX请求st到'comment.php',而不是JS代码。检查控制台的网络选项卡以准确找到错误。在这里发布'comment.php'的代码也有帮助。 –

+0

检查你的语法文章 – Sibidharan

+0

好吧,让我发表comment.php – jake123

回答

0

我能解决这个问题我的错误是在 index.php

的index.php

<div id='comment_type_area' class='comment_type_area'> 
      <form method='POST'> 
       <input type='text' class='comment' post_id='<?php $shared_id2; ?>' id='text_comment' placeholder='Write a Comment'></input> 
       <input type='submit' id='post_button' ></input> 
      </form> 

我错过了方法部分,也改变了文本区域输入

感谢所有你的人民输入