卡住爲什麼這不起作用,任何人有任何想法?它應該更新按鈕,我想這樣做,只是顯示的其他在結束所有的時間Ajax調用不返回期望值
function friendToggle(type,user,elem){
var conf = confirm("Press Ok to confirm the '" +type+ "' action for user " + user);
if(conf != true){
return false;
}
O(elem).innerHTML = 'please wait...';
params = user
request = new ajaxRequest()
request.open("POST", "friendSystem.php", true)
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
request.setRequestHeader("Content-length", params.length)
request.setRequestHeader("Connection", "close")
request.onreadystatechange = function(){
if(this.readyState == 4){
if(this.responseText == "friend_request_sent"){
O(elem).innerHTML = 'OK Friend Request Sent';
}else if(this.responseText == "unfriend_ok"){
O(elem).innerHTML = '<button onclick="friendToggle(\'friend\',\'echo $view;\',\'friendBtn\')">Request As Friend</button>';
}else {
alert(request.responseText);
O(elem).innerHTML = 'Try again later';
}
}
}
request.send("type="+type+"&user="+user);
}
這是它調用的代碼:
if($_POST['type'] == "friend")
{
$friendCount = mysqli_fetch_row(querySQL("SELECT COUNT(*) FROM friends WHERE user='$user' AND accepted='1' OR friend='$user' AND accepted='1'"));
$blockCount1 = mysqli_fetch_row(querySQL("SELECT COUNT(*) FROM blockedusers WHERE blocker='$user' AND blockee='$view' LIMIT 1"));
$blockCount2 = mysqli_fetch_row(querySQL("SELECT COUNT(*) FROM blockedusers WHERE blocker='$view' AND blockee='$user' LIMIT 1"));
$rowCount1 = mysqli_fetch_row(querySQL("SELECT COUNT(*) FROM friends WHERE user='$view' AND friend='$user' AND accepted='1' LIMIT 1"));
$rowCount2 = mysqli_fetch_row(querySQL("SELECT COUNT(*) FROM friends WHERE user='$user' AND friend='$view' AND accepted='1' LIMIT 1"));
$rowCount3 = mysqli_fetch_row(querySQL("SELECT COUNT(*) FROM friends WHERE user='$view' AND friend='$user' AND accepted='0' LIMIT 1"));
$rowCount4 = mysqli_fetch_row(querySQL("SELECT COUNT(*) FROM friends WHERE user='$user' AND friend='$view' AND accepted='0' LIMIT 1"));
if($friendCount[0] > 99){
echo"$user currently has the maximum number of friends and cannot accept any more";
}elseif($blockCount1[0] > 0){
echo "$user has you blocked, we cannot proceed.";
}elseif($blockCount2[0] > 0){
echo"You must first unblock $user in order to friend them.";
}elseif($rowCount1[0] >0 || $rowCount2[0] > 0){
echo"You are already friends with $user.";
}elseif($rowCount3[0] >0){
echo"You have a pending friend request already sent to $user.";
}elseif($rowCount4[0] > 0){
echo"$user has requested to friend with you first. Check your friend requests";
}else{
querySQL("INSERT INTO friends VALUES('$user','$view','0')");
echo"friend_request_sent";
}
}
它的意思回顯正確的錯誤信息,但沒有。也永遠不會發送好友請求發送消息
顯然'responseText'既不是'friend_request_sent'也不是'unfriend_ok'。不確定你想要我們做什麼。如果您確實發回了正確的回覆,請提供有關此問題的更多信息。否則,請更新您的客戶端代碼以匹配您從服務器獲得的響應,或者更新您的服務器端代碼以返回正確的響應。 –
在你的if(this.responseText ==「friend_request_sent」)之前加上alert(this.responseText);'並且比較你的結果! – GeoffreyB
Geoffrey,它沒有效果,只是提出了一個空白的警報框,沒有響應文本,即使這個人不是朋友 – user1886385