我正在對ajax調用一個php文件,並且該php文件沒有返回給我輸出。 Chrome瀏覽器顯示上述錯誤。 Loadmessage.php正在返回輸出,但問題在於提取。未捕獲的SyntaxError:意外的令牌[
$.ajax({
url: "loadmessage.php",
type: "POST",
data:{
'sender': sender,
'receiver': receiver,
},
success: function(response){
var result = JSON.parse(response); //Chrome showing error over here
console.log("Result is " +result);
console.log()
for(var i in result){
$("#m-"+id).append('<p class = "shout_msg">' +result[i]+ '</p>');
$("#m-"+id).scrollTop($("#m-"+id)[0].scrollHeight);
}
}
});
這裏是我的loadmessage.php代碼
<?php
$sender_id = 0;
$receiver_id = 0;
session_start();
if(isset($_SESSION['login_user'])) {
}
else {
header('location: ChatLog.php');
}
if(isset($_REQUEST['sender']) AND isset($_REQUEST['receiver'])){
$sender = $_REQUEST['sender'];
$receiver = $_REQUEST['receiver'];
require_once 'dc_chat.php';
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$result = $mysqli -> query("SELECT id from users where username LIKE '{$sender}'");
$row = mysqli_fetch_row($result);
$sender_id = $row[0];
echo $sender_id;
$result = $mysqli -> query("SELECT id from users where username LIKE '{$receiver}'");
$row = mysqli_fetch_row($result);
$receiver_id = $row[0];
$sql = $mysqli -> query("SELECT * from messagse where sender_id = $sender_id AND receiver_id = $receiver_id");
while($row = mysqli_fetch_array($sql)) {
$array[] = $row[3].": ".$row[4];
}
echo json_encode($array);
}
?>
我應該在哪裏進行更正?
嘗試添加空間AFER'<?php'並請刪除'?>'。你不需要那 – Umair 2014-10-31 07:58:02