2016-01-25 57 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> 

我錯過了方法部分,也改變了文本區域輸入

感謝所有你的人民輸入