在ajax调用之后不加载div内容

时间:2017-11-23 09:09:55

标签: php jquery mysql ajax

我有一个目标网页,我在fetch_pages.php中使用Ajax分页从fetch_pages.php加载内容,在div中,当用户点击按钮并重新加载时,我正在调用Ajax connect()调用div函数,fetch_pages.php重新加载时,它变为空,无法得到确切的解。请帮助。

<?php session_start(); include 'db.php'; //include config file $UserID=$_SESSION['uid']; $UserType=$_SESSION['utype']; $GLOBALS['lks']=0; $GLOBALS['cmnts']=0; $GLOBALS['disabled']=""; //sanitize post value $page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH); //throw HTTP error if page number is not valid if(!is_numeric($page_number)){ header('HTTP/1.1 500 Invalid page number!'); exit(); } //get current starting point of records $position = (($page_number-1) * $item_per_page); ?> <!---post start --> <div id="mainsectionID"> <?php //fetch records using page position and item per page. $results = $linkID1->query("select slno,posts,img_link,video_link,likes,comments,shares,post_date,post_time,UserID from user_posts where UserID='$UserID' or UserID in(select MyFriendsUserID from user_connections where MyUserID='$UserID') or UserID in(select MyUserID from user_connections where MyFriendsUserID='$UserID') order by slno desc LIMIT $position, $item_per_page") or die(mysqli_error()); //output results from database ?> <?php while($row = mysqli_fetch_array($results)) { //fetch values $CUID=$row['UserID']; $stmt = $linkID1->prepare("select Name,Company,Designation,UserType from user_details where UserID=?"); $stmt->bind_param("s", $CUID); $stmt->execute(); $stmt->bind_result($Name2,$Company2,$Designation2,$UType); $stmt->fetch(); $stmt->close(); $UT2=''; if($UType=='A') { $UT2='Advertiser'; } else if($UType=='P') { $UT2='Publisher'; } $stmt = $linkID1->prepare("select ProfilePic from user_picture where UserID=?"); $stmt->bind_param("s", $CUID); $stmt->execute(); $stmt->bind_result($PPic); $stmt->fetch(); $stmt->close(); ?> <div class="mainsection" id="mainsection<?php echo $row[slno]; ?>"> <div> <div class="pull-left postimage"><?php echo "<img src=profile_pic/".$PPic ." />"; ?></div> <div class="pull-left posttext"> <div class="postname"><?php echo $Name2; ?></div> <p><?php echo $UT2." - ".$Designation2." - ".$Company2; ?></p></div> <div class="clear"></div> <div class="postdowntxt"><p><?php echo $row['posts']; ?></p></div> <hr> </div> <div class="btnclasess" id="likescommentID<?php echo $row[slno]; ?>"> <div class="likescomment"><?php dataLC($linkID1, $row['slno'],$CUID); ?><a style="padding-right: 7px" href="#"><?php if($GLOBALS['lks']==0){echo '';}else{ echo $GLOBALS['lks']." Likes"; } ?></a><a href="#"><?php if($GLOBALS['cmnts']==0){echo '';}else{ echo $GLOBALS['cmnts']." Comments"; } ?></a></div> <div class="pull-left likebtn"><button <?php echo $GLOBALS['disabled']; ?> class="btn" id="likeButton<?php echo $row[slno]; ?>" onClick="connect(<?php echo $row[slno]; ?>)"><i class="fa fa-thumbs-up" style="margin-right: 6px;"></i>Like</button></div> <button class="pull-left btnhideshow show_hide" data-toggle="collapse" data-target="#demo<?php echo $row['slno']; ?>"><li class="fa fa-comments show_hide" style="margin-right: 6px;"></li>Comment</button> <button class="pull-left btnhideshow show_hide"><li class="fa fa-share-alt show_hide" style="margin-right: 6px;"></li>Share</button> <div class="clear"></div> <div class="clear"></div> </div> ......rest codes goes here....... <?php function dataLC($linkID1, $val, $CUID) { $UserID=$CUID; $LgUserID=$_SESSION['uid']; $stmt = $linkID1->prepare("select likes,comments from user_posts where slno=?"); $stmt->bind_param("s", $val); $stmt->execute(); $stmt->bind_result($lksD,$cmntsD); $stmt->fetch(); $stmt->close(); $GLOBALS['lks']=$lksD; $GLOBALS['cmnts']=$cmntsD; $stmt = $linkID1->prepare("select count(slno) from user_posts_likes where MyUserID=? and FrUserID=? and PostID=?"); $stmt->bind_param("sss", $UserID,$UserID,$val); $stmt->execute(); $stmt->bind_result($cnt); $stmt->fetch(); $stmt->close(); if($cnt>=1) { $GLOBALS['disabled']="disabled"; } else { $GLOBALS['disabled']="enabled"; } $stmt = $linkID1->prepare("select count(slno) from user_posts_likes where MyUserID=? and FrUserID=? and PostID=?"); $stmt->bind_param("sss", $UserID,$LgUserID,$val); $stmt->execute(); $stmt->bind_result($cnt2); $stmt->fetch(); $stmt->close(); if($cnt2>=1) { $GLOBALS['disabled']="disabled"; } else { $GLOBALS['disabled']="enabled"; } $stmt = $linkID1->prepare("select count(slno) from user_posts_likes where MyUserID=? and FrUserID=? and PostID=?"); $stmt->bind_param("sss", $LgUserID,$UserID,$val); $stmt->execute(); $stmt->bind_result($cnt3); $stmt->fetch(); $stmt->close(); if($cnt3>=1) { $GLOBALS['disabled']="disabled"; } else { $GLOBALS['disabled']="enabled"; } } ?> <script type="text/javascript"> function connect(num) { $.ajax({ type: "POST", url: "user-likes.php?id="+num, success: function(data) { if(data=='1') { $("#likescommentID"+num).load(" #likescommentID"+num); } } }); } </script>

的部分代码
Microsoft.VisualStudio.SnapshotDebugger.AzureAppServices.Standalone

1 个答案:

答案 0 :(得分:-1)

问题解决了,再次称为分页部分。日Thnx