對不起,如果標題是一點..模糊我不能把它釘住。jQuery頁面刷新不能讀取或執行php
因此,我正在開發一個朋友請求系統,它的工作原理與Facebook的概念類似。所以你得到一個請求,並列出他們沒有頁面重新加載。
但是我得到div'刷新'或所以我認爲我不能測試的PHP這是我有一個問題,我會發布相關的代碼和文件下面。
它看起來有點長,但它在現實中應該太糟糕了。我的php代碼應該繼續執行正在查看updateFriendBox.php中的數據庫的查詢,但它似乎沒有這樣做。我的代碼也可能很亂,所以我很抱歉。
myaccount.php
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script language="javascript" type="text/javascript">
function refreshDiv()
{
$.get('updateFriendBox.php', function(data){$('#refresh').html(data);});
}
$(function()
{
refreshDiv();
setInterval(refreshDiv, 5000);
});
function box(x){
if($('#'+x).is(":hidden")){
$('#'+x).slideDown(200);
} else {
$('#'+x).hide();
}
}
</script>
<?php
$addBox = '<div style="display:inline; padding:5px;">
<a href="#" onclick="return false" onmouseup="javascript:box(\'fRequ\');">Show/Hide Friend Requests</a>
</div>';
// a bit further down in the code where its all called:
<a href="#" class="tooltip"><? echo $addBox; ?></span></a>
<div class="friendSlide" id="fRequ" style="height:240px; overflow:auto;">Your friend requests: <br />
<div id="refresh"> <?php // this is where the refresh call is ?>
</div>
</center>
</div>
</div>
</div>
updateFriendBox.php:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script language="javascript" type="text/javascript">
function acceptFriendRequest(x) {
var url = "friendParse.php";
$.post(url,{ request: "acceptFriend", reqID: x}, function(data){
$("#req"+x).html(data).show().fadeOut(5000);
});
}
function denyFriendRequest(x) {
var url = "friendParse.php";
$.post(url,{ request: "denyFriend", reqID: x}, function(data){
$("#req"+x).html(data).show().fadeOut(5000);
});
}
</script>
</head>
<body>
<?php
include 'dbc.php';
$sql = "SELECT * FROM friendRecu WHERE mem2='" . $_SESSION['user_id'] . "' ORDER BY id ASC LIMIT 10";
$query = mysql_query($sql)or die(mysql_error());
$num_rows = mysql_num_rows($query);
if($num_rows < 1) {
echo "No friend requests";
} else {
while($row = mysql_fetch_array($query)){
$requestID = $row['id'];
$req = $row['mem1'];
$sqlName = mysql_query("SELECT full_name FROM users WHERE id='$req'");
while($row = mysql_fetch_array($sqlName)){
$requesterName = $row['full_name'];
}
echo '<hr /><table width="100%", cellpadding="5"><tr><td width="17%" align="left"><div style="overflow:hidden; height:50px; color:white;"></div></td> <td width="83%"><a href=viewmembers.php?uid=' . $req . '">' . $requesterName . '</a> added you as a friend
<span id="req' . $requestID . '">
<a href="#" onclick="return false" onmousedown="javascript:acceptFriendRequest(' . $requestID . ');">Accept</a>
||
<a href="#" onclick="return false" onmousedown="javascript:denyFriendRequest(' . $requestID . ');">Deny</a>
</span></td></tr>
</table>';
}
}
?>
嘗試使用控制檯進行調試js。 '使用此代碼並將結果更新到我們:'$ .get('updateFriendBox.php',function(data){('#refresh')。html(data); alert('Load was performed。') ; });' – 2012-03-09 19:25:05
事實上,你需要使用螢火蟲或一些日誌記錄,以找出哪裏出了問題,或至少獲得更多的信息。 – 2012-03-09 19:28:18
它一直彈出「執行加載」 – Jack4 2012-03-09 19:35:27