[Simple] Beginner AJAX script not working, stuck on opening XMLHttpRequest
- by Julian H. Lam
Hopefully, this question isn't too juvenile to ask - but here goes:
I'm trying to learn AJAX, and I'm stuck on a simple content-fetch. Here is my code:
request = getHTTPObject();
function useHttpResponse() {
if (request.readyState == 4) {
document.getElementById("p").innerHTML = request.responseText;
}
}
function update_p() {
request.open("GET",content.html,true);
request.onreadystatechange = useHttpResponse;
}
getHTTPObject is correctly defined, and returns a proper XMLHttpObject. As you probably guessed from the excerpt, the element I am trying to update is id'd "p". It calls the script correctly when a button is clicked, no problem there.
The script seems to stop at line 8, at request.open. There's no error, and the script silently ignores anything afterward.
I don't think I've missed anything, but of course, I probably did. Where did I go wrong?
Thanks!