Ajax uses a programming model with display and events. Events are users actions which call functions associated with web page. Forms and buttons are used to achieve interactivity. DOM allows to connect page elements with actions and also to retrieve data from XML files provided by the server.
To retrieve data on the server, XMLHttpRequest provides two methods: open and send.
Data furnished by the server will be found in the attributes of the XMLHttpRequest object:
- responseXml for an XML file or
- responseText for a plain text.
Take note that a new XMLHttpRequest object has to be created for each new file to load.
We have to wait for the data to be available to process it, and in this purpose, the state of availability of data is given by the readyState attribute of XMLHttpRequest.