我正在尝试按下按钮时发送好友请求,但我的问题是当页面刷新时我收到两个警报,当我点击按钮时,因为我的php在我的html代码中是内联的?感谢
public class Base {
public virtual void Validate(){return; };
}
[NotMapped]
public class Derived:Base {
public override void Validate(){DoSomethingWithData(); return; };
}
答案 0 :(得分:0)
//In your main page
<div class="alert alert-success fade in">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<p><strong>Ey!</strong></p>
<?
$getusersquery=mysqli_query($link,"Select * from 360tery where userid='$otherusersid' LIMIT 4 ");
while($row5=mysqli_fetch_array($getusersquery))
{
//here, added userid to use in button
$userid=$row5['userid'];
$userusername=$row5['username'];
$useremail=$row5['Email'];
$userprofilepicture=$row5['Profilepicture'];
$userfirstname=$row5['firstname'];
$userlastname=$row5['lastname'];
$user_profile_pic='/users/'.$userusername.'/profilepicture/'.$userprofilepicture;
$userphoto = "<img src='.$user_profile_pic' id='avatarimg' class='img-circle' height='85' width='85'> <br> <br>";
echo'<div class="well">';
echo '<p><strong> '.$userfirstname.' '.$userlastname.'</strong> </p>';
echo'<p>'.$userusername.'</p>';
echo $userphoto;
//Here changed form to button
echo '<button onclick="send_request('.$userid.')" name="addfriend" class="btn btn-warning btn-xs">Add Friend</button>';
echo '</div>';
}
?>
//Javascript - Ajax submit function
<script>
function send_request(userid){
$.ajax({
type: "POST",
url: "ajax.php",
data: "userid="+userid,
cache: false,
success: function(result){
alert(result);
}
});
}
</script>
//In ajax.php page
<?
if(isset($_POST['userid'])){
$userid=$_POST['userid'];
if(your_condition_like_mysqliupdate_or_other_with_$userid) {
echo "Friend Request sent";
} else {
echo "Friend Request NOT sent";
}
}
?>
请试试这个。确保您已关闭DIV alert
。我没有在你的代码中看到它
对main.php的一些更新
data: {otherusersid: "$otherusersid", myuserid: "$myuserid"},
,此处您正在使用name
而不是myuserid
$query=mysqli_query($link,"SELECT userid from 360tery where Email='$email'");
,此处您正在使用username
而不是Email
Username
,Email
作为username
,email
等,请使用变量,mysql表,mysql中设计的列。