我从PHP获取了roomId的未定义变量消息。我在一个警告框中得到它,因为我在PHP中回应它并在Javascript中提醒函数。
这是我的ajax功能:
function setMessages(roomId, username, message){
$.ajax({
type: "get",
url: "http://www.sinansamet.nl/chatdistract/ajax/setMessages.php",
data: { roomId:roomId, username:username, message:message },
success: function(html) {
alert(html);
}
});
}
我的PHP:
<?php
$roomdId = $_GET['roomId'];
$username = $_GET['username'];
$message = $_GET['message'];
echo $username;
?>
调用ajax:
$(document).on("click", "#messageSubmit", function(){
var username = window.localStorage["username"];
var message = $("#message").val();
setMessages(roomId, username, message);
alert(roomId + username + message);
});
答案 0 :(得分:3)
我认为这只是一个错字。你写了
$roomdId = $_GET['roomId'];
//^there is an extra d
应该是
$roomId = $_GET['roomId'];