A Fresh Start
After a long time away from blogging and not being serious about it this is going to be a fresh start of this blog. I am hoping to be posting much more regularly and learning new things on the way
var xmlHttp = new XMLHttpRequest(); please note that JavaScript IS case sensitive so if you make a mistake in the declaration it will not work. Now abit about what this code does. The line of code is placed outside any JavaScript function so that it is available globally to all the functions that will be written later on and any changes that have been made to it in one function will affect the next time it is being used. This way of coding is somewhat lazy but works as good as any other method. A sort of better way of achieving the same outcome would be to declare the request object in the first function that you want to make the request from and send it as a param to any other function that will be using it. if(XMLHttpRequest) than create a new instance of the object by executing the declaration above. Otherwise declare the request object as follows xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");. At this point I would also like to say that the variable in which I declare the request object I call it xmlHttp but please feel free to use any name that makes sence to you because you will be the one writing the code but please make sure that if anyone else was to read your code it should be readable and understandable by everyone.xmlHttp.open("get", "openThis.txt", true). What this is doing is pretty much self explaintory it uses the "get" method to get information from the file "openThis.txt" in a true asychronise manner. At this point I would just like to remind you that for HTML forms there are usually two methods of dealing with them, the POST method and the GET method. Where the POST method sends data somewhere and the GET method gets data from somewhere. xmlHttp.onreadstatechange;. Now since you will be communicating with the server there are some steps and states you have to go through before you can actually get stuff off the server and onto the client machine. The state in which the connection is in. The way you find out about this is using the readyState property of the request object. The readyState property may have 1 of 5 values that are listed below:| Value | Meaning |
|---|---|
| 0 | Unintialised or connection established but nothing is being done |
| 1 | Initialised or connection established and something has started to be done |
| 2 | Request has been sent |
| 3 | Interactive or the request is in the process of execution |
| 4 | Ready or request has been executed and the server is ready for the next one |
xmlHttp.onreadystatechange = function (){};.