你好,我想从文本区获得文本,并在数据库中注册,但不工作,哪里是问题,谢谢大家。$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')");
发布于 2016-05-26 18:56:54
你缺少钥匙。将您的数据更改为:
data: { get_text : $("#post_text").val() },
并且您的类型是PHP,所以在POST
文件中使用$_POST['get_text']
。
发布于 2016-05-26 18:53:34
您正在使用post方法。所以使用$_POST‘’get_text‘;
发布于 2016-05-26 18:53:37
问题是,您正在进行POST,并试图获取GET形式的值。
使用:
$get_text = $_POST['get_text'];
mysqli_query($Connection, "INSERT INTO posts VALUES('$ID', '$get_text')");
https://stackoverflow.com/questions/37458709
复制相似问题