2017-03-12 24 views
0

通知タブを機能させようとしていますが、正しく機能していないようです。ドロップダウンは正常に動作していますが、newfriends.phpへのajaxコールは正しく機能していません。火かき棒で見るとドロップダウンに表示される結果はありません。かなり混乱します。 (ドロップダウンメニューは、ヘッダ内に配置され、セッションが初期化されている場合のみ表示されることに注意) ここではjQueryのに使用されるAJAXである:ここで動的ajaxドロップダウンメニューが機能しない

function load_notifications(view=''){ 
    $.ajax({ 
     url: "notification/new_friends.php", 
     method: "POST", 
     data:{view:"view"}, 
     dataType:"json", 
     success: function(data){ 

      $(".dropdown-menu").html(data.notification); 
if(data.unseen_notification>0){ 
    $(".badge1").html(data.unseen_notification); 
} 
    } 

    }); 
     //$(".dynamic-notification").load("notification/pm_n.php"); 
    // $(".dynamic-notification-f").load("notification/new_friends.php"); 
}; 
load_notifications(); 
$(document).on("click",".count_friend", function(){ 
    load_notifications('yes'); 
}); 
//loads every 2 seconds for chat 
setInterval(function(){load_notifications();},2000); 

はnew_friends.phpコンテンツである:

<?php 
include '../includes/dbconfig.inc.php'; 

if (isset($_POST['view'])) { 

if($_POST['view'] !=''){ 
    $update="update friends set count='1' where friend_one=:session and count='0'"; 
    $stmt=$conn->prepare($update); 
    $stmt->bindValue(":session", $_SESSION['uname']); 
    $stmt->execute(); 
} 
$sql123="select id from friends where friend_two=:sess_uname and count='0'"; 
    $stmt123=$conn->prepare($sql123); 
    $stmt123->bindValue(":sess_uname", $_SESSION['uname']); 
    $stmt123->execute(); 
    $request_count=$stmt123->fetchColumn(); 
    //$count_friend=$stmt123->rowCount(); 
    /*$sql_f_count="select *from user where user_id=:session_id and activated='1' limit 1"; 
    $stmt_f_count=$conn->prepare($sql_f_count); 
    $stmt_f_count->bindValue(":session_id", $_SESSION['id']); 
    $stmt_f_count->execute(); 
    $user_details=$stmt_f_count->fetchAll(); 
    $friend_badge=$user_details[0]['friend_count_badge'];*/ 
    require "notification/friend_request_notification.php"; 
// $new_friends="<span class='dropdown'><a href='#' data-placement='bottom' class='btn dropdown-toggle' data-toggle='dropdown' title='Friend Requests' data-html='true'><span class='count_friend' style=' height:33px; width:30px;'><span class='badge1 label label-pill'>".$count."</span><img src='img/logo/group-button-white.png' style='height:25px; width:27px;' alt='new_friends_alert'></span></a><ul class='dropdown-menu'></ul></span>";  
//if($request_count[0]>0){ 
    //$new_friends="<a href='#' data-placement='bottom' class='btn' data-trigger='focus' title='Friend Requests' data-toggle='popover' data-html='true' data-content='".$friend_requests."'><span class='count_friend' style=' height:33px; width:30px;'><img src='img/logo/group-button-white.png' style='height:25px; width:27px;' alt='new_friends_alert'></span><span class='badge'>".$friend_badge."</span></a>"; 
    /*}else{ 
    $new_friends="<a href='all_notifications.php'><img src='img/logo/group-button-black.png' style='height:25px; width:27px;' alt='new_friends_alert'></a>"; 
    }*/ 
//echo $new_friends; 
//} 
    $data=array(
     'notification'=>$friend_requests, 
     'unseen_notification' =>$request_count[0][0] 
    ); 
} 
echo json_encode($data); 

や友人のためのコードが出力要求:

<?php 
//error_reporting(0); 
require_once 'includes/dbconfig.inc.php'; 
$sql = "select * from friends where friend_two=:session and accepted='0' order by friends_date_made asc"; 
$stmt = $conn->prepare($sql); 
$stmt->bindparam(":session", $_SESSION['uname']); 
$stmt->execute(); 
$numrows = $stmt->fetchAll(PDO::FETCH_ASSOC); 
$friend_requests=""; 
if ($numrows < 1) { 
    $friend_requests = "You do not have any friend requests"; 
    echo "$friend_requests"; 
    exit(); 
} else { 
    foreach ($numrows as $i=>$row1) { 
     $reqid = $row1['friend_id']; 
     $user1 = $row1['friend_one']; 
     $datemade = $row1['friends_date_made']; 
     $datemade1 = strftime("%B %d, %y", strtotime($datemade)); 
     $sql = "SELECT * FROM user WHERE uname=:user1 LIMIT 1"; 
     $stmt = $conn->prepare($sql); 
     $stmt->bindparam(":user1", $user1); 
     $stmt->execute(); 
     $thumbrow = $stmt->fetchAll(PDO::FETCH_ASSOC); 
     $user1avatar = $thumbrow[$i]['avatar']; 
     $user1id=$thumbrow[$i]['user_id']; 

     if ($user1avatar =="") { 
      $user1pic = '<img src="img/avatardefault.png" height="50" style="float:left;" width="50" alt="'.$user1.'" class="user_pic">'; 
     } else { 
     $user1pic = '<img src="../user/user/'.$user1id.'/'.$user1avatar.'" height="50" style="float:left;" width="50" alt="'.$user1.'" class="user_pic">'; 

     } 
     $friend_requests .= '<li><div id="'.$reqid.'" float="right" class="friendrequests"> 
     <a href="home.php?u='.$user1.'">'. $user1pic .'</a> 
       <div class="user_info '.$reqid.'" id="'.$reqid.'"><small>' . $datemade1 . '</small> 
       <a href="home.php?u='.$user1.'">'.$user1.'</a> is requesting your friendship<br /><br /> 
     <button id="'.$reqid.'" name="'.$_SESSION['uname'].'" sess="'.$_SESSION['id'].'" class="accept_btn btn btn-warning">Accept</button><span class="show-spinner"></span> or 
     <button id="'.$reqid.'" name="'.$_SESSION['uname'].'" sess="'.$_SESSION['id'].'" class="reject_btn btn btn-warning">Reject</button> 
     </div> 
     </div><hr></li>'; 


    } 

} 

答えて

1

あなたは現在data:{view:"view"}を持っています。 これは、要求の本文に文字列'view'を渡すことを意味します。以下のようなものに

変更を:

function load_notifications(thisview=''){ 
    var theData = { 
     view: thisview 
    } 
    $.ajax({ 
     url: "notification/new_friends.php", 
     method: "POST", 
     data: theData, 
     dataType:"json", 
     success: function(data){ 
+0

はまだ運メイト放火犯は、内部サーバエラーであると私は慎重すぎてすべてのクエリを確認することを言いません。これ以上の提案 – jackal4me

+0

'error_reporting(E_ALL);を追加することがあります ページに移動し、PHPエラーが発生していないかどうかを確認してください。 はまた、MySQLのエラーをオンにする: '$ dbh->のsetAttribute(PDO :: ATTR_ERRMODE、PDO :: ERRMODE_EXCEPTION);' ( '$のdbh'は、データベースの名前です) –

+0

私はすでにDBコネクションを設定していますPDOを使用した場合と同じように、問題は解決しません。 – jackal4me

関連する問題