你好,我想从文本区域获取文本并在数据库中注册,但无法工作,问题出在哪里,谢谢大家。 $get_text 显示空值。
<script type="text/javascript">
$(function() {
$(".new_post").click(function(){
var get_text = $("#post_text").val();
$.ajax({
type: "POST",
url: "ajax/ajax_new_post.php",
data: get_text,
success: function() {
alert(get_text);
$('#post_text').val('');
//$(this).parents(".show").animate({ backgroundColor: "#003" }, "slow")
//.animate({ opacity: "hide" }, "slow");
}
});
return false;
});
});
</script>
<body>
<textarea id="post_text" placeholder="What's on your mind?"></textarea>
</body>
ajax_new_post.php
$get_text = $_GET['get_text'];
mysqli_query($Connection, "INSERT INTO posts VALUES('$ID', '$get_text')");
请您参考如下方法:
您缺少 key 。将您的数据更改为:
data: { get_text : $("#post_text").val() },
您的类型是 POST,因此在 PHP 文件中使用 $_POST['get_text']。






