I'm having some troubles trying to execute an ajax call. It is stored in chat.js (added in the html head) and it does a call to 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');
})()
I checked with alert()
and the onreadystatechange
event doesn't work.