AJAX en Google Code University
Google Code University dentro de sus cursos nos ofrece un tutorial bueno sobre AJAX, ahí encontramos teoría, la forma de como crear el objeto xmlhttprequest y un ejemplo, lo malo es que está en inglés, pero a buen entendedor pocas palabras.
Siempre es bueno leer temas como este por ejemplo para poder tener una idea más amplia y de ahí cada uno poder formar nuestro estilo en lo referente a la programación, allí encontré ejemplos de código de como tratar el objeto XMLHTTPRequest… espero les sirva.
Adjunto los códigos:
var obj;
function ProcessXML(url) {
// native object
if (window.XMLHttpRequest) {
// obtain new object
obj = new XMLHttpRequest();
// set the callback function
obj.onreadystatechange = processChange;
// we will do a GET with the url; "true" for asynch
obj.open("GET", url, true);
// null for GET with native object
obj.send(null);
// IE/Windows ActiveX object
} else if (window.ActiveXObject) {
obj = new ActiveXObject("Microsoft.XMLHTTP");
if (obj) {
obj.onreadystatechange = processChange;
obj.open("GET", url, true);
// don't send null for ActiveX
obj.send();
}
} else {
alert("Your browser does not support AJAX");
}
}
La función de proceso.
function processChange() {
// 4 means the response has been returned and ready to be processed
if (obj.readyState == 4) {
// 200 means "OK"
if (obj.status == 200) {
// process whatever has been sent back here:
// anything else means a problem
} else {
alert("There was a problem in the returned data:\n");
}
}
}
Tomado de http://code.google.com/edu/ajax/tutorials/ajax-tutorial.html
Excellent post.
Nice Article