gpt4 book ai didi

javascript - AJAX PHP评论框userid=0?回复=""?

转载 作者:行者123 更新时间:2023-11-29 22:42:39 34 4
gpt4 key购买 nike

当我在textarea中输入文本时,什么也没有出现。它显示:

cveUser name :jason123User id :1 forum_insert.js?t=1427284551:44 ResponseText{"reply_id":24,"user_id":0,"reply":"","username":"jason123","profile_img":"/booking/images/user.png"}

user_id 和回复不起作用。

forum_insert.php

<?php

if(isset($_POST['task']) && $_POST['task'] == 'forum_insert')
{

$user_id =(int) $_POST['user_id'];
$reply =addslashes(str_replace("\n", "<br>" , $_POST['reply-text']));

$std = new stdClass();
$std->reply_id = 24;
$std->user_id = $user_id;
$std->reply = $reply;
$std->username = "jason123";
$std->profile_img = "/booking/images/user.png";

echo json_encode($std);

}
else
{
header('Location: /booking/forumrm.php');
}
?>

forum_insert.js

$(document).ready(function(){

$('#reply').click(function(){
reply_click();
});
});

function reply_click(){

//text within textarea which the person has entered.
var text = $('#reply-text').val();
var user_id = $('#user_id').val();
var username = $('#username').val();




if(text.length >0 && user_id != null)
{
$('.forum-insert-container').css('border','1px solid #e1e1e1' );
console.log(text + "User name :" + username + "User id :" + user_id);

$.post("/booking/forum_insert.php" ,
{
task :"forum_insert",
userId : user_id,
reply : text
}

)

.error(
function()
{
console.log("Error");
}
)

.success(

function(data)
{
forum_insert(jQuery.parseJSON(data));
console.log("ResponseText" +data);

}
);



}
else{
$('.forum-insert-container').css('border','1px solid blue' );
console.log("The text area was empty");
}


//remove text from textarea.
$('#reply-text').val("");
};

function forum_insert(data)
{
var t ='';
t +='<li class="forum-holder" id="_'+data.reply_id+'">';
t +='<div class="user-img">';
t +='<img src="'+data.profile_img+'" class="user-img-pic" />';
t +='</div>';

t +='<div class="forum-body">';
t +='<h3 class="username-field">'+data.username+'</h3>';

t +='<div class="forum-text">'+data.reply+'</div>';
t +=' </div>';

t +='<div class="forum-buttons-holder">';
t +='<ul>';
t +='<li class="delete-btn">X</li>';
t +='</ul>';
t +='</div>';
t +='</li>';

$('.forum-holder-ul').prepend(t);

}

forum_box.php

<?php foreach($forum as $key => $forum ):?>

<li class="forum-holder" id="_1">

<div class="user-img">
<img src="images/user.png" class="user-img-pic" />
</div>

<div class="forum-body">
<h3 class="username-field">
jason123
</h3>

<div class="forum-text">
therdgdthbtrhdr
therdgdthbtrhdr
dthbtrhdrtherdgdthbtrhdr
tdvgdhdfhfhherdgdthbtrhdr
therdgdthbtrhdr
therdgdthbtrhdr
</div>
</div>

<div class="forum-buttons-holder">
<ul>
<li class="delete-btn">X</li>
</ul>
</div>
</li>
<?php endforeach; ?>

最佳答案

您使用的是 userId 而不是 user_id

$.post("/booking/forum_insert.php" ,
{
task :"forum_insert",
userId : user_id,
reply : text
}

$user_id =(int) $_POST['user_id'];

更改为

$user_id =(int) $_POST['userId'];

相同
$reply =addslashes(str_replace("\n", "<br>" , $_POST['reply-text']));

$reply =addslashes(str_replace("\n", "<br>" , $_POST['reply']));

关于javascript - AJAX PHP评论框userid=0?回复=""?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29255959/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com