Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The code you posted is missing one important ingredient: the function stateChanged.</p> <p>If you don't quite understand the code you posted yourself, then what happens is when the call to getchats.php is complete, a function "stateChanged" is called and that function will be responsible for handling the response. Since the script you're calling and the function itself is prefixed with "gets" then I'm pretty sure the response is something you're going to be interested in. </p> <p>That aside, there are a number of ways to improve on the code you posted. I'd guess it works by declaring a single "xmlHttp" object and then making that available to every function (because if it doesn't, the stateChanged function has no way of getting the response). This is fine until you run an AJAX request before the last one (or last few) haven't replied yet, which in that case the object reference is overwritten to the latest request each time.</p> <p>Also, any AJAX code worth its salt provides functionality for sucess and failure (server errors, page not found, etc.) cases so that the appriopiate message can be delivered to the user.</p> <p>If you just want to use AJAX functionality on your website then I'd point you in the direction of <a href="http://www.jquery.com" rel="nofollow noreferrer">jQuery</a> or a <a href="http://www.prototypejs.org" rel="nofollow noreferrer">similar</a> <a href="http://www.mootools.net" rel="nofollow noreferrer">framework</a>.</p> <p>BUT if you actually want to understand the technology and what is happening behind the scenes, I'd continue doing what you're doing and asking specific questions as you try to build a small lightweight AJAX class on your own. This is how I done it, and although I use the jQuery framework today.. I'm still glad I know how it works behind the scenes.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload