tags:

views:

24

answers:

2

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!

+2  A: 

content.html is not quoted. Try putting it inside a single/double quote.

oks16
Thanks for the comment - already tried, but the result is the same.
Julian H. Lam
you did not call send function?request.send(null)
oks16
Cheers, that did it.
Julian H. Lam
+1  A: 
T.J. Crowder
Hi T.J., that's exactly what I'm trying to do here. Just learning the underlying concepts, should the need arise. :)
Julian H. Lam
@Julian: Smart thing to do.
T.J. Crowder