Forum

Cannot run ajax on Hiawatha

Fred
22 September 2015, 16:52
Hi Hugo,

Could you please tell me if Hiawatha support AJAX script?
Here is my simple example...
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>

<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

</body>
</html>

When I click on the 'Change Content' button nothing is happening..
Could you please tell me if there is an setting in hiawatha.conf that could stop ajax from working?

Thank you
Hugo Leisink
22 September 2015, 17:12
Yes, Hiawatha supports AJAX requests. In fact, any webserver will, because there is no difference between a AJAX request and a normal HTTP request. The only difference is that an AJAX request is triggered by a Javascript and a normal HTTP request by a user interaction and an AJAX request has one extra HTTP header: X-Requested-With: XMLHttpRequest.

An AJAX request will, as any other HTTP request, show up in your access logfile. If it's not there, something went wrong with the sending of the request. If it is there, something went wrong with handling the response.
This topic has been closed.