我想使用JQuery Ajax長民意調查和PHP做一個像facebook一樣的股票代碼。jquery ajax長輪詢附加錯誤parsererror(SyntaxError:意外的標記<)
我的腳本顯示:error parsererror(SyntaxError:Unexpected token <)。
請問我的腳本中出現這些錯誤的原因是什麼?
我的jQuery腳本:
function addmsg(from_id, detail, time){
$("#updatetime").append(
"<div class='upbox1'>"+ from_id +" "+ detail +" "+ time +"</div>"
);
}
function waitForMsg(){
$.ajax({
type: "GET",
url: "upsidenew2.php",
async: true,
cache: false,
timeout:50000,
dataType: "json",
success: function(data){
if(data) {
addmsg(data);
}
setTimeout(
waitForMsg,
1000
);
},
error: function(XMLHttpRequest, textStatus, errorThrown){
addmsg("error", textStatus + " (" + errorThrown + ")");
setTimeout(
waitForMsg,
15000);
}
});
}
$(document).ready(function() {
waitForMsg();
});
upsidenew2.php
include_once("mysessionone.php");
if($session->logged_in){
global $dbh;
$myid = $session->id;
//Find out follow And followers
$q = mysqli_query($dbh,"SELECT * FROM follow WHERE friend_one='$myid' OR friend_two='$myid'") or die(mysqli_error($dbh));
if ($row = mysqli_fetch_array($q)) {
$f_id = $row['friend_one'];
$f2_id = $row['friend_two'];
//convert follow and followers id's
$s1 = mysqli_query($dbh,"SELECT bdid,username FROM users WHERE `bdid`='".$f_id."' OR `bdid`='".$f2_id."'") or die(mysqli_error($dbh));
while ($row = mysqli_fetch_array($s1)) {
$fbdid = $row["bdid"];
$fusername = $row['username'];
//find out post id's of user's and followers
$g = mysqli_query($dbh,"SELECT parent_id FROM updateside WHERE `from_id`='".$fusername."' OR `to_id`='".$fbdid."' OR `from_id`='".$session->username."' OR `to_id`='".$session->id."' GROUP BY parent_id DESC") or die(mysqli_error($dbh));
while ($row = mysqli_fetch_array($g)) {
$parent = $row['parent_id'];
date_default_timezone_set('Asia/Dhaka');
$timestamp = date("M j, y; g:i a", time() - 2592000);
//here is user's related post to echo
$u = mysqli_query($dbh,"SELECT * FROM updateside WHERE `parent_id`='".$parent."' AND `created` > '".$timestamp."' ORDER BY created DESC") or die(mysqli_error($dbh));
while ($row = mysqli_fetch_array($u)) {
$data['from_id'] = $row['from_id'];
$data['parent_id'] = $row['parent_id'];
$data['to_id'] = $row['to_id'];
$data['sub'] = $row['sub'];
$data['detail'] = $row['detail'];
$data['img'] = $row['img'];
$data['time'] = $row['created'];
header('Content-type: application/json');
echo json_encode($data);
exit;
}
}
break;
}
} else { echo '<div class="mass1">No Update</div>'; }
} else { echo '<div class="mass1">Login to see</div>'; } //session close
你能通過瀏覽器以某種方式檢查你的AJAX請求的響應數據嗎? (可能是網絡檢查員)我認爲這個問題可能在你的PHP腳本的響應中。 –
網絡巡視員顯示ok響應數據 – joy
這不是我的意思。響應數據是否以'<?開頭? –