AJAX-Tips Tutorials
AJAX-TipsXMLHttpRequest Properties
In developing Ajax, one of the most common codes you’ll be using is the XMLHttpRequest. Getting things done in Ajax without using this type of code is really impossible. This code represents the communication between program and the server. Even though users don’t see the literal interaction between the server and the program, underneath in any website and program that’s Ajax based is an intricate communication between the server and the website that’s even independent of the user.XMLHttpRequest cannot work alone; there are different modes of communication and interaction that you have to consider. For example, what if the website cannot really communicate to the server? What should be communicated with the server and what information and where it will be implemented? There are actually three properties that any Ajax programmer should remember and each of them has their own specific function.
- Onreadystatechange – this type of property in XMLHttpRequest is very important in the sense that you have to do something with the information that you request from the property. Onreadystatechange will set the program or the website to facilitate the information or data received. This is very basic considering you want to have a fully functional website that can be used as a tool.
- readyState – this is an option that you can…or you should if you have a fluctuating server or would like to do something about the server. The server will have different reactions or responses to the request based on the speed or the status of the server. This could also be used if there are options regarding the server. For example, if there is no response from the server there should be another function that will run or a response that will be given to the web page. Each readyState property is assigned with a value which are usually like this: 0 for no response or has not started, 1 if the request has been set up to be executed, 2 if the request has been sent to the server, 3 if it’s still in the process and 4 if the request is all done. Readystate could also be used to stream information and functions from one program to another.
- responseText – this is the last property that usually happens in XMLHttpRequest. When everything has been set, you still have to retrieve the information with a code. Even though Ajax is a very smart programming language, you still have to make the program really smart telling them to do things. After readyState has executed a specific function from the server, you will have to retrieve the result. This is good in the sense that you are directing everything a response should do. The basic use of responseText will show its importance when you direct the response to a specific part of the webpage or part of the program.
Sponsored Links
