I decided to dabble in some Ajax this afternoon and am having some issues with it. Here's the JS:
Code Javascript:function ajax() { var req; if (window.XMLHttpRequest) req = new XMLHttpRequest(); else if (window.ActiveXObject) { try {req = new ActiveXObject("Msxml2.XMLHTTP")} catch (e) { try {req = new ActiveXObject("Microsoft.XMLHTTP")} catch (e) {} } } req.onreadystatechange = function() {showResponse(req);} req.open('GET', 'http://127.0.0.1/test.php?ajax=yes', true); } function showResponse(response) { if (response.readyState == 4) { if (response.status == 200) { alert(response.responseText); } } }
test.php:
Nothing is received from the server - the response.readyState always seems to be 1. I'm trying this out locally using XAMPP, but I'd be surprised if this is a problem.PHP Code:<?php
echo 'hello';
?>
This is pretty much identical to all the examples out there, such as the one on devmo. What am I doing wrong? I'm stumped. Any enlightenment is greatly appreciated!






Bookmarks