<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://php.apsique.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>Php y otras yerbas - Disectando XMLHttpRequest - Comentarios</title>
 <link>http://php.apsique.com/ajax/XMLHttpRequest</link>
 <description>Comentarios para &quot;Disectando XMLHttpRequest&quot;</description>
 <language>es</language>
<item>
 <title>De nada.
Mientras más me</title>
 <link>http://php.apsique.com/ajax/XMLHttpRequest#comment-82077</link>
 <description>&lt;p&gt;De nada.&lt;br /&gt;
Mientras más me explico, más me complico.&lt;/p&gt;
</description>
 <pubDate>Mon, 16 Jun 2008 07:17:28 -0700</pubDate>
 <dc:creator>clbustos</dc:creator>
 <guid isPermaLink="false">comment 82077 at http://php.apsique.com</guid>
</item>
<item>
 <title>Mil gracias por tu articulo,</title>
 <link>http://php.apsique.com/ajax/XMLHttpRequest#comment-82060</link>
 <description>&lt;p&gt;Mil gracias por tu articulo, la verdad es que me he leido como 20.. en un ratito, me has sacado de sendos apuros.&lt;/p&gt;
&lt;p&gt;Tienes una forma muy peculiar de explicar las cosas tks ^^&lt;/p&gt;
</description>
 <pubDate>Sat, 14 Jun 2008 17:18:16 -0700</pubDate>
 <dc:creator>Silvanha</dc:creator>
 <guid isPermaLink="false">comment 82060 at http://php.apsique.com</guid>
</item>
<item>
 <title>He probado el objeto ajax, pe</title>
 <link>http://php.apsique.com/ajax/XMLHttpRequest#comment-57743</link>
 <description>&lt;p&gt;He probado el objeto ajax, pero la unica falla k le encontre fue k no me deja mandar archivos en un formulario, es con lo unico k he tenido problemas, pero el resto de cosas, la raja. Si alguien ha intentado mandar archivos y le resulto por favor avise.&lt;/p&gt;
</description>
 <pubDate>Mon, 27 Nov 2006 06:42:10 -0800</pubDate>
 <dc:creator>BlackCat</dc:creator>
 <guid isPermaLink="false">comment 57743 at http://php.apsique.com</guid>
</item>
<item>
 <title>Gracias por el articulo</title>
 <link>http://php.apsique.com/ajax/XMLHttpRequest#comment-6895</link>
 <description>&lt;p&gt;Lei el comentario y me parece algo excelente que alguien se preocuope por subir estos comentarios a la red, ya que los que empezamos a programar con estas tecnologias nos damos una idea mas amplia de realizar nuestros trabajos de una manera eficiente.&lt;/p&gt;
&lt;p&gt;Gracias&lt;/p&gt;
</description>
 <pubDate>Mon, 22 Aug 2005 08:22:39 -0700</pubDate>
 <dc:creator>juliocesar</dc:creator>
 <guid isPermaLink="false">comment 6895 at http://php.apsique.com</guid>
</item>
<item>
 <title>Corrección</title>
 <link>http://php.apsique.com/ajax/XMLHttpRequest#comment-3728</link>
 <description>&lt;p&gt;Ok, ok, me equivoqué. No se debe ocupar &lt;code&gt;escape&lt;/code&gt; para enviar las variables, sino &lt;code&gt;encodeURLComponent&lt;/code&gt;. Hay que ver como funciona en IE.&lt;/p&gt;
</description>
 <pubDate>Thu, 09 Jun 2005 21:09:01 -0700</pubDate>
 <dc:creator>clbustos</dc:creator>
 <guid isPermaLink="false">comment 3728 at http://php.apsique.com</guid>
</item>
<item>
 <title>¿Que onda con UTF-8? Sets de caracteres, la web y Ajax</title>
 <link>http://php.apsique.com/ajax/XMLHttpRequest#comment-3684</link>
 <description>&lt;p&gt;Objetivo&lt;br /&gt;
Al finalizar este artículo, el lector, si ha entendido algo, será capaz de&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Entender de forma bastante vaga que son las codificaciones de caracteres&lt;/li&gt;
&lt;li&gt;Decir, ¡A,ha!, cuando lea ASCII, ISO-8859-1, Unicode y UTF-8&lt;/li&gt;
</description>
 <pubDate>Thu, 09 Jun 2005 14:45:10 -0700</pubDate>
 <dc:creator>Php y otras yerbas, por Clbustos (trackback)</dc:creator>
 <guid isPermaLink="false">comment 3684 at http://php.apsique.com</guid>
</item>
<item>
 <title>Error en ejemplo de Ajax</title>
 <link>http://php.apsique.com/ajax/XMLHttpRequest#comment-3540</link>
 <description>&lt;p&gt;Estimados:&lt;br /&gt;
Si han ocupado IE para ver el ejemplo de este artículo, les lanzará un error de javascript. El error fue olvidarme de poner &quot;var&quot; para &quot;valor&quot; y &quot;xml&quot; al buscar los valores de los input. En firefox funciona sin problemas. Mil perdones.&lt;br /&gt;
En la noche espero tener corregido el error, que de verdad es mínimo. Por ahora, el zip con los archivos para probar en el servidor de cada cual está corregido.&lt;br /&gt;
Actualización:Acabo de llegar y corregí el error. Debería funcionar en el engendro.&lt;/p&gt;
</description>
 <pubDate>Mon, 30 May 2005 13:33:55 -0700</pubDate>
 <dc:creator>clbustos</dc:creator>
 <guid isPermaLink="false">comment 3540 at http://php.apsique.com</guid>
</item>
<item>
 <title>Of course!</title>
 <link>http://php.apsique.com/ajax/XMLHttpRequest#comment-3538</link>
 <description>&lt;p&gt;Simpático artículo, mi estimado. Gracias por el link :)&lt;br /&gt;
Por lo menos desde mi óptica, trabajar en Ajax, en HTTP-RPC o como quieran llamarlo no es tan complicado, si sabes lo que estás haciendo. Claro, hay que saber un poco más de lo requerido para trabajar con un sistema clásico de cgi, pero el esfuerzo vale la pena.&lt;br /&gt;
Y a todo esto, feliz cumpleaños. Podrías ponerte un avatar, para identificarte rápido...&lt;/p&gt;
</description>
 <pubDate>Mon, 30 May 2005 13:00:35 -0700</pubDate>
 <dc:creator>clbustos</dc:creator>
 <guid isPermaLink="false">comment 3538 at http://php.apsique.com</guid>
</item>
<item>
 <title>¿Y qué es Ajax?</title>
 <link>http://php.apsique.com/ajax/XMLHttpRequest#comment-3537</link>
 <description>&lt;p&gt;Por cierto - y no es que pretenda autopromocionarme - ¿leíste el artículo sobre Ajax que escribí hace un tiempo?...&lt;/p&gt;
&lt;p&gt;http://www.mouse.cl/2005/rep/04/15/index.asp&lt;/p&gt;
&lt;p&gt;Quizá sirva para quienes no se han interiorizado en el tema ;)&lt;/p&gt;
&lt;p&gt;¡Salute!&lt;/p&gt;
</description>
 <pubDate>Mon, 30 May 2005 12:53:53 -0700</pubDate>
 <dc:creator>Francotirador</dc:creator>
 <guid isPermaLink="false">comment 3537 at http://php.apsique.com</guid>
</item>
<item>
 <title>Disectando XMLHttpRequest</title>
 <link>http://php.apsique.com/ajax/XMLHttpRequest</link>
 <description>&lt;h2&gt;Intro&lt;/h2&gt;
&lt;p&gt;Hace mucho, mucho tiempo atrás, &lt;a href=&#039;/node/106&#039;&gt;comenté&lt;/a&gt; sobre los diversos métodos para recoger información desde el servidor sin recargar la página. Ocupé el término &lt;em&gt;RPC vía HTTP&lt;/em&gt; para dar cuenta de este fenómeno, pero desde el artículo de Adaptative Path llamado &lt;a href=&#039;http://www.adaptivepath.com/publications/essays/archives/000385.php&#039;&gt;ajax: a new approach to web applications&lt;/a&gt;, el nombre &lt;em&gt;Ajax&lt;/em&gt; se ha incrustado en el inconsciente colectivo de todos nosotros.&lt;/p&gt;
&lt;p&gt;Como bien dice nuestro estimado James, Ajax es un enfoque, más que una tecnología específica, que tiene como antecedente trucos tan sucios como recoger información en iframes escondidos, tal como lo hace mi querido &lt;a href=&#039;http://www.ashleyit.com/rs/jsrs/test.htm&#039;&gt;jsrs&lt;/a&gt;. Ok, ok, hasta ahora no estoy diciendo nada que no haya dicho, pero sirve de introducción&lt;/p&gt;
&lt;!--break--&gt;
&lt;h2&gt;Breve explicación de como funciona HTTP&lt;/h2&gt;
&lt;p&gt;Recordemos, ante que nada, que la WWW funciona con un modelo de cliente-servidor, siendo el cliente el navegador (Firefox, Mozilla, Opera o el &lt;acronym title=&#039;Internet Explorer&#039;&gt;engendro&lt;/acronym&gt;) y el servidor un demonio http (Apache, Zeus y el &lt;acronym title=&quot;IIS&quot;&gt;otro engendro&lt;/acronym&gt;).&lt;/p&gt;
&lt;p&gt;En una carga de página normal, el cliente envía lo que se llama una &lt;a href=&#039;http://www.w3.org/Protocols/HTTP/Request.html&#039;&gt;petición&lt;/a&gt; al servidor. Cuando ponemos en la barra del navegador &quot;http://php.apsique.com&quot;, enviamos el siguiente texto al servidor por un puerto, que generalmente es el 80:&lt;/p&gt;
&lt;pre&gt;GET   /	HTTP/1.0&lt;/pre&gt;
&lt;p&gt;Como vemos en la &lt;a href=&#039;ftp://ftp.isi.edu/in-notes/rfc2616.txt&#039;&gt;especificación del protocolo HTTP&lt;/a&gt;, existen diversos métodos a través de los cuales podemos decir al servidor que tipo de petición debemos hacer. Tenemos los clásicos GET Y POST, pero también otros como HEAD, DELETE y PUT. Lo importante es recordar que GET sirve para recuperar información sin alterar la fuente, en tanto que POST nos permite entregar información que altera el recurso.&lt;/p&gt;
&lt;p&gt;El servidor, al recibir una petición, nos entrega una respuesta, que es también un texto. Esta respuesta siempre comienza con un código, que indica el estado de la operación. Entre ellos tenemos el esperado 200 (todo ok), 301 (movido permanentemente) y los temidos 403 (prohibido), 404 (no existe recurso) y 500 (error del cgi). Después de esta respuesta, generalmente se ofrece el tipo MIME del contenido (texto, xml, imagen) y el contenido propiamente tal. Por ejemplo, para una página típica de mi sitio&lt;/p&gt;
&lt;pre&gt;Date: Mon, 30 May 2005 07:12:49 GMT
Server: Apache/1.3.33 (Unix)  (Gentoo/Linux) mod_ruby/1.2.4 Ruby/1.8.2(2004-12-25) PHP/4.3.11
X-Powered-By: PHP/4.3.11
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

200 OK&lt;/pre&gt;
&lt;p&gt;A estas alturas del partido, si no han abandonado, se preguntarán porque les estoy dando tanto la lata. La respuesta es simple: si bien en una carga de página normal todo este enredo lo manejan de forma casi mágica el cliente y el servidor de forma automática, al ocupar Ajax hay que manejar todo esto, en el fondo, &lt;em&gt;a mano&lt;/em&gt;. Si bien ya existen bastantes aplicaciones que ocultan esta información, si no tienen claro el proceso de consulta y respuesta, no van a poder entender bien como funciona el proceso en realidad y de donde surgen los errores. &lt;/p&gt;
&lt;h2&gt;Ajax&lt;/h2&gt;
&lt;p&gt;Ya teniendo en nuestras cabezas el proceso de consulta-respuesta, podemos empezar a trabajar en Ajax. Si quieren un texto muy bueno, y en el cual se basará la discusión, lean &lt;a href=&#039;http://jibbering.com/2002/4/httprequest.html&#039;&gt;Using the XML HTTP Request object&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;El nombre Ajax es un acrónimo de &quot;Asynchronous JavaScript + XML&quot;. Ahora, &lt;em&gt;no es necesario ocupar XML&lt;/em&gt;. Si, tal como lo oyeron. Si bien siempre suena bonito ocupar esta siglita, la verdad es que la consulta y recepción son simples textos; así, si bien se puede ocupar XML para ordenar la cosa, no estamos limitados por ello.&lt;/p&gt;
&lt;h2&gt;Javascript al mando&lt;/h2&gt;
&lt;p&gt;A partir del Explorer 6 (si no me equivoco) y de Mozilla 1.6, tenemos a nuestra disposición el objeto XMLHttpRequest. El problemita es que en IE (para variar) se accede a el con &lt;pre&gt;new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;)&lt;/pre&gt; o &lt;pre&gt;new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;)&lt;/pre&gt; dependiendo de la versión del IE. Por tanto, lo mejor es crear una función que nos entregue el objeto, la cual diría algo como:
&lt;div class=&#039;code&#039;&gt;&lt;div class=&quot;hl-main&quot;&gt;&lt;ol class=&quot;hl-main&quot;&gt;&lt;li&gt;&amp;nbsp;&lt;span class=&quot;hl-reserved&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;get_xmlhttp&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;  &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;ActiveXObject&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;Msxml2.XMLHTTP&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;catch&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;  &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;   &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;ActiveXObject&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;Microsoft.XMLHTTP&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;  &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;catch&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;E&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;   &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;  &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &amp;amp;&amp;amp; &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;typeof&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;XMLHttpRequest&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;  &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;XMLHttpRequest&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;}&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Una vez que tenemos el objeto, para hacer una petición debemos abrir la conexión y enviar la consulta. Para ello utilizados&lt;/p&gt;
&lt;div class=&#039;code&#039;&gt;&lt;div class=&quot;hl-main&quot;&gt;&lt;ol class=&quot;hl-main&quot;&gt;&lt;li&gt;&amp;nbsp;&lt;span class=&quot;hl-identifier&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;metodo&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;contenido&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Recuerden que si utilizamos &quot;GET&quot;, bastará con poner las variables en el url, en el clásico formato&lt;/p&gt;
&lt;pre&gt;script.php?variable1=valor1&amp;variable2=valor2&lt;/pre&gt;
&lt;p&gt;Escapando los carácteres extraños con &lt;em&gt;encodeURIComponent&lt;/em&gt;. Si ocupan POST, deben enviar el contenido en la variable &lt;em&gt;contenido&lt;/em&gt; en &lt;em&gt;send&lt;/em&gt;, aunque por ahora no sé muy bien como se hace (apenas tenga el dato, aviso)&lt;/p&gt;
&lt;p&gt;Normalmente, nosotros deseamos saber en que momento el servidor nos entrega la respuesta y realizar una función con ésta. Para ello, existe una función de xmlhttp llamada &lt;em&gt;onreadystatechange&lt;/em&gt;, la cual se ejecuta cada vez que cambia el estado de la conexión. Sabiendo que la propiedad &lt;em&gt;readyState&lt;/em&gt; se pone a &lt;em&gt;4&lt;/em&gt; cuando la respuesta ha sido recibida, podemos mejorar el código haciendo&lt;/p&gt;
&lt;div class=&#039;code&#039;&gt;&lt;div class=&quot;hl-main&quot;&gt;&lt;ol class=&quot;hl-main&quot;&gt;&lt;li&gt;&amp;nbsp;&lt;span class=&quot;hl-identifier&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;metodo&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;onreadystatechange&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;  &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;readyState&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;   &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;  &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;
 &lt;p&gt;&lt;em&gt;callback&lt;/em&gt; es el nombre de una función que recibirá el resultado de la llamada al servidor&lt;/p&gt;
 &lt;p&gt;Si revisamos el objeto xmlhttp una vez recibida la respuesta, veremos que cuenta con los siguientes métodos de interés&lt;/p&gt;
&lt;dl&gt;
&lt;dt&gt;getAllResponseHeaders()&lt;/dt&gt;&lt;dd&gt;Nos entrega todas las cabeceras de respuesta desde el servidor&lt;/dd&gt;
&lt;dt&gt;status&lt;/dt&gt;&lt;dd&gt;El código de estatus de la petición (normalmente, 200)&lt;/dd&gt;
&lt;dt&gt;responseText&lt;/dt&gt;&lt;dd&gt;Texto literal de la respuesta&lt;/dd&gt;
&lt;dt&gt;responseXML&lt;/dt&gt;&lt;dd&gt;Objeto XMLDocument, el cual se puede analizar con las funciones de DOM típicas, como getElementById y similares.De aquí la &lt;em&gt;X&lt;/em&gt; de Ajax&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2&gt;El servidor&lt;/h2&gt;
&lt;p&gt;Desde el lado del servidor, la cosa es muy sencilla. Podemos enviar las cabeceras que queramos, así como el texto que se nos antoje. Por ejemplo, podemos utilizar el código 304 para decir que la página no ha tenido actualización desde la última vez que se visitó&lt;/p&gt;
&lt;p&gt;Un dato importante es que &lt;em&gt;solamente&lt;/em&gt; si definimos el tipo de contenido como xml con &lt;/p&gt;
&lt;pre&gt;Content-type: text/xml&lt;/pre&gt;
&lt;p&gt;La propiedad &lt;em&gt;responseXML&lt;/em&gt; tendrá un valor en el objeto xmlhttp&lt;/p&gt;
&lt;h2&gt;Ejemplo&lt;/h2&gt;
&lt;p&gt;Esa sería la teoría del asunto, mis estimados. Ahora, nada mejor que un buen ejemplo para que vean el bicho en operaciones. Como siempre, pueden encontrar los archivos como adjunto al final del post&lt;/p&gt;
&lt;script language=&quot;JavaScript&quot; src=&quot;/demos/xmlhttprequest/httprequest.js&quot;&gt;&lt;/script&gt;
&lt;div style=&quot;padding:5px; margin:5px; border:1px solid grey&quot;&gt;
Texto: &lt;input type=&quot;text&quot; id=&quot;valor&quot; /&gt;
XML: &lt;input type=&#039;checkbox&#039; id=&#039;xml&#039; value=&quot;1&quot; /&gt;
&lt;button value=&quot;probar&quot; onClick=&quot;probar_XMLHttpRequest()&quot;&gt;&lt;b&gt;Testear&lt;/b&gt;&lt;/button&gt;
&lt;h2&gt;Estatus&lt;/h2&gt;
&lt;pre id=&quot;estatus&quot; style=&#039;border:3px ridge red;&#039;&gt;Nada por ahora&lt;/pre&gt;
&lt;h2&gt;Cabecera&lt;/h2&gt;
&lt;pre id=&quot;cabecera&quot; style=&#039;border:3px ridge red;&#039;&gt;Nada por ahora&lt;/pre&gt;
&lt;h2&gt;Cuerpo&lt;/h2&gt;
&lt;pre id=&quot;texto&quot; style=&#039;border:3px ridge red;&#039;&gt;Nada por ahora&lt;/pre&gt;
&lt;h2&gt;Propiedades y métodos objeto xmlhttprequest&lt;/h2&gt;
&lt;pre id=&quot;objeto&quot; style=&#039;border:3px ridge red;&#039;&gt;Nada por ahora&lt;/pre&gt;
&lt;/div&gt;</description>
 <comments>http://php.apsique.com/ajax/XMLHttpRequest#comments</comments>
 <category domain="http://php.apsique.com/lenguajes/javascript">JavaScript</category>
 <category domain="http://php.apsique.com/categoria/temas_generales/gran_red">La gran Red</category>
 <category domain="http://php.apsique.com/lenguajes/php">PHP</category>
 <category domain="http://php.apsique.com/categoria/temas_generales/programacion">Programación</category>
 <category domain="http://php.apsique.com/lenguajes/xml">XML</category>
 <category domain="http://php.apsique.com/ajax">Ajax</category>
 <enclosure url="http://php.apsique.com/files/xhttprequest.zip" length="1587" type="application/x-zip-compressed" />
 <pubDate>Mon, 30 May 2005 01:24:57 -0700</pubDate>
 <dc:creator>clbustos</dc:creator>
 <guid isPermaLink="false">453 at http://php.apsique.com</guid>
</item>
</channel>
</rss>
