XMLHttp Request object for AjaxThe first step that we have to learn in AJAX is the XMLHTTP request. This we will be using in every Ajax code we write. A good understanding of this will help us in analyzing and developing complex codes.
An agent or a brokerThis XMLHttp object is an agent between our application at client side and our programming code at server end. It sends data and collects the return data from the server.
Now we understood that creation of this XMLHttp request is an issue with the browser of the user ( or client ). So the user browser must able to create this XMLHttp object. Unfortunately the old browsers doest not support this and can't create XMLHttp object. So we have to find out first this object is created or not. If the browser fails to create the object then we must give error message saying about the browser issue.
Even if the browser are capable of creating our XMLHttp request they differ in the way they create it. FireFox create the object in a different way than Internet Explorer ( IE ). So based on this we will develop the code and note that we can use this same set of code ( to create the XMLHttp object ) in all pages where we will be using Ajax. Let us develop the code.
We will try with first trying with a simple request like this
The above line will return true for Firfox and Safari so we can create an object. For IE we will use ActiveXObject to create the object. Depending on the type of ActiveXObject support which depends on version of IE we will create the object. If in all fail in crating the object then we will return error message.
Now let us write the function to initialize the HMLHttp Request object
//To use this function we will create an object like this.
Ajax & PHP scripts Creating XMLHttp object in different browsers Sample Code: Get Method of Ajax form submission Server Clock:: Display real-time date and time of server Dependant drop down list box using Ajax & PHP Email validation using Ajax in a form Getting customer details by entering customer id using Ajax Progress Bar using Ajax Progress Bar using MySQL PHP & Ajax Displaying Message at client side using Ajax & PHP Web page HTML form validation using Ajax and PHP Form validation with onBlur event using Ajax and PHP
Json support in PHP json_encode to generate Json string from PHP Array data Json Data formatting to return database records to main script Searching MySql database as we type using Ajax Displaying all records based on selection of a drop down list box