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')");
我怎样才能使按钮并回车键后财产以后?我似乎无法弄清楚。请帮忙。
从你描述的问题奠定了与AJAX请求st到'comment.php',而不是JS代码。检查控制台的网络选项卡以准确找到错误。在这里发布'comment.php'的代码也有帮助。 –
检查你的语法文章 – Sibidharan
好吧,让我发表comment.php – jake123