我遇到了一些麻烦,试图执行ajax调用。它存储在chat.js(在HTML头部添加)和它的调用getChatHistory.php获取响应的问题
chat.js:
function getChatHistory(user1, user2){
var response = 'fail';
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
response = response + xmlhttp.responseText;
} else {
response = "Error:" + hmlhttp.status;
}
xmlhttp.open('GET', 'getChatHistory.php?user1=' + user1 + '&user2=' + user2);
xmlhttp.send();
}
return response;}
getChatHistory.php:
<?php
echo "the php talks";
?>
的index.html:
<script>
(function(){
alert(getChatHistory('user1', 'user2');
})()
我检查了alert()
和onreadystatechange
事件不起作用。
你是什么意思它不工作?它不是射击?打开你的控制台并检查错误 –
一个问题是你有''hmlhttp.status''而不是'xmlhttp.status'' – Andrew
似乎在index.html中的alert命令中缺少结尾“)”? – Malvolio