0
我具有以下HTML表格的输入值:通过使用上MySQL查询的jquery
<form method="post" action="">
<input type="hidden" name="userid" id="user" value="<?php echo $user ?>"/>
<textarea name="comment" class="subcomment_form" id="ctextarea<?php echo $suggestid ?>"></textarea>
<input type="submit" value="Post" id="<?php echo $suggestid ?>" class="form_btn" style="margin-top: 5px"/>
</form>
以下JS代码:
$('.form_btn').live("click",function()
{
var ID = $(this).attr("id");
var user= $("input[name=userid]").val();
var comment= $("#ctextarea"+ID).val();
var dataString = 'comment='+ comment + '&suggestid=' + ID + 'user' + user;
if(comment=='')
{
alert("Please Enter Comment Text");
}
else
{
$.ajax({
type: "POST",
url: "action/subcomment.php",
data: dataString,
cache: false,
success: function(html){
$("#commentload"+ID).append("html");
$("#ctextarea"+ID).val('');
$("#ctextarea"+ID).focus();
}
});
}
return false;
});
,并按照subcomment.php文件PHP代码:
if($_POST['comment'])
{
$comment=$_POST['comment'];
$suggestid=$_POST['suggestid'];
$user=$_POST['user'];
$sql = "INSERT INTO user_suggestions_comments (uvd_id, user_id, usc_comment) VALUES ('".$_POST['suggestid']."', '".$_POST['user']."','".$_POST['comment']."')";
mysql_query($sql);
}
我的问题是,<input type="hidden" name="userid" id="user" value="<?php echo $user ?>"/>
的值不会传递到php文件并传递textarea内容。我需要在JS代码中更改它以使其工作?
是的,我是假设,他只是通过形式是我不知道为什么他要把它变成一个数据串... –
非常感谢你们俩,通过在用户面前加入&:) –
看起来他正在将它改为数据字符串,因为suggestId i从不会正常提交的数据构建。 但是我会说最好将数据字符串中的名称保持原样,就像表单自然提交一样。只是让事情更清楚。 – Chris