<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Johan de Bruin &#187; AJAX</title>
	<atom:link href="http://www.johandebruin.com/t/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johandebruin.com</link>
	<description>Programación en php, tutorial de api wordpress y posicionamiento en buscadores seo.</description>
	<lastBuildDate>Sun, 05 Feb 2012 15:18:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Actualizar tu feed de twitter con AJAX</title>
		<link>http://www.johandebruin.com/actualizar-tu-feed-de-twitter-con-ajax/</link>
		<comments>http://www.johandebruin.com/actualizar-tu-feed-de-twitter-con-ajax/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 12:43:13 +0000</pubDate>
		<dc:creator>Johan de Bruin</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Programacion]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=183</guid>
		<description><![CDATA[Hoy con la nueva categoria AJAX os mostrare un código en AJAX que os permitira actualizar los mensajes de twitter sin tener que actualizar la página. Para ello, tendremos que dividir el código de programación en 2 archivos. el código de AJAX se mostrará en el archivo cliente, mientras que el código twitterfeed.php será de [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy con la nueva categoria AJAX os mostrare un código en AJAX que os permitira actualizar los mensajes de twitter sin tener que actualizar la página. Para ello, tendremos que dividir el código de programación en 2 archivos. el código de AJAX se mostrará en el <strong>archivo cliente</strong>, mientras que el código <strong>twitterfeed.php </strong>será de donde obtendrá los nuevos feed el código en AJAX.<br />
<span id="more-183"></span><br />
Primero definiremos el código javascript necesario para poder actualizar el feed de twitter. Emplazaremos este código junto al resto de código javascript de la página (orden porfavor).</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #006600; font-style: italic;">//Primero creamos el objeto XMLHttpRequest que nos permite establecer conexiones HTTP</span>
xmlhttp <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//Con esta función actualizamos el contenido de cualquier div con el de algún archivo</span>
<span style="color: #003366; font-weight: bold;">function</span> makerequest<span style="color: #009900;">&#40;</span>serverPage<span style="color: #339933;">,</span> objID<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>objID<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    xmlhttp.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span> serverPage<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    xmlhttp.<span style="color: #660066;">onreadystatechange</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>xmlhttp.<span style="color: #660066;">readyState</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">4</span> <span style="color: #339933;">&amp;&amp;</span> xmlhttp.<span style="color: #000066;">status</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            obj.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> xmlhttp.<span style="color: #660066;">responseText</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    xmlhttp.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Ahora, debemos definir el código HTML, la primera vez que mostremos el feed de twitter lo haremos con PHP con tal de que los buscadores puedan rastrearlo, luego usaremos un botón para actualizar el feed usando AJAX y el usuario no tenga que estar refresando la página web.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;ul&gt;
    &lt;div id=&quot;twitterfeed&quot;&gt;
        <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;twitterfeed.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;/div&gt;
&lt;/ul&gt;
&lt;center&gt;&lt;input type=&quot;button&quot; onclick=&quot;makerequest('twitterfeed.php','twitterfeed')&quot; value=&quot;Actualizar&quot;&gt;&lt;/center&gt;</pre></div></div>

<p>Ahora solo nos queda crear <strong>twitterfeed.php</strong>, para ello usaremos una función que ya publique con anterioridad: <a title="feed twitter php" href="http://www.johandebruin.com/mostrar-feed-de-busqueda-en-twitter/">Mostrar feed de busqueda en twitter</a></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> twitterfeed<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;li&gt;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'johandebruin'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'5'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Y con esto queda terminado el código, podeis verlo funcionando en esta página web: <a href="http://www.blognexusone.es">Blog nexus one</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/actualizar-tu-feed-de-twitter-con-ajax/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

