Inicio > Ajax, Google, XMLHttpRequest > AJAX en Google Code University

AJAX en Google Code University

jueves, 12 de junio de 2008 Dejar un comentario Ir a comentarios

googleGoogle 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:

01.var obj;
02. 
03.function ProcessXML(url) {
04.// native  object
05. 
06.if (window.XMLHttpRequest) {
07.// obtain new object
08.obj = new XMLHttpRequest();
09.// set the callback function
10.obj.onreadystatechange = processChange;
11.// we will do a GET with the url; "true" for asynch
12.obj.open("GET", url, true);
13.// null for GET with native object
14.obj.send(null);
15.// IE/Windows ActiveX object
16.} else if (window.ActiveXObject) {
17.obj = new ActiveXObject("Microsoft.XMLHTTP");
18.if (obj) {
19.obj.onreadystatechange = processChange;
20.obj.open("GET", url, true);
21.// don't send null for ActiveX
22.obj.send();
23.}
24.} else {
25.alert("Your browser does not support AJAX");
26.}
27.}

La función de proceso.

01.function processChange() {
02.// 4 means the response has been returned and ready to be processed
03.if (obj.readyState == 4) {
04.// 200 means "OK"
05.if (obj.status == 200) {
06.// process whatever has been sent back here:
07.// anything else means a problem
08.} else {
09.alert("There was a problem in the returned data:\n");
10.}
11.}
12.}

Tomado de http://code.google.com/edu/ajax/tutorials/ajax-tutorial.html

Categories: Ajax, Google, XMLHttpRequest Tags:
  1. lunes, 4 de agosto de 2008 a las 18:57 | #1

    Excellent post.

  2. jueves, 17 de julio de 2008 a las 06:14 | #2

    Nice Article

  1. Sin trackbacks aún.