我正在尝试创建一种请求,其中注册会员可以看到其他注册会员的帖子。他们可能会选择与他们联系,然后才能对帖子发表评论。我想要的是使用jQuery将请求发送到PHP,然后PHP将状态connection requested
插入到数据库中。当成员看到请求时,他可以选择接受或拒绝该请求。如果他接受,状态将更改为you are connected with this member
。
我知道有类似的问题,但不完全像我的,有人应该请你帮忙。
'cont_email' is email of member sending request
'email_cont' is email receiving the request
'status' is the status of the connection
'counter' is request increment
这是我的HTML部分:
<input name="connect" type="button" value="Connect with <?php echo"$mem_com[name]";?>" class="intag2" onclick="connt()"/>
PHP部分正常运行。我唯一的问题是通过jQuery将请求发送到PHP并返回到jQuery,后者现在根据成员活动显示连接状态。
答案 0 :(得分:0)
更新回答:
将此内容放入用户将看到的文件中(我假设当用户登陆时,get参数将被传递到此页面?):
<input id="connectButton" name="connect" type="button" value="<?php echo $status;?>" class="intag2" />
<script type="text/javascript">
var email_cont = '<?=$_GET[email_cont]?>';
var cont_email = '<?=$_GET[email]?>';
$('#connectButton').click(function() { // add a click event to the button (no need for onclick)
var counter = 0;
$.ajax({
url: 'requests.php?cont_email='+cont_email+'&email_cont='+email_cont+'&counter='+counter,
success: function( data ) {
$('#connectButton').val(data); // set the button value to the new status.
$('#connectButton').unbind('click'); //stop the user clicking the button loads of times.
}
});
});
</script>
然后将其放在名为requests.php的文件中:
<?php
$email_cont = $_GET['email_cont'];
$cont_email = $_GET['cont_email'];
$counter = $_GET['counter'];
$status = "Connection Sent!";
$insert = mysql_query("INSERT INTO request VALUES ('','$cont_email','$email_cont','$status', '$counter', NOW())");
$result = mysql_query($query);
if(!result){
//If it fails to run the SQL return an error.
echo "Connection Failed!";
}else{
//If all goes well, return the status
echo $status;
}
?>
未经测试,但应该按照您的要求进行测试。