<?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>Swekee Team Developer &#187; AJAX</title>
	<atom:link href="http://developer.swekee.com/category/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://developer.swekee.com</link>
	<description>Blog de los desarrolladores de Swekee</description>
	<lastBuildDate>Fri, 05 Sep 2008 02:43:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Utilizando XAJAX 0.5 en PHP</title>
		<link>http://developer.swekee.com/2008/09/04/utilizando-xajax-05-en-php/</link>
		<comments>http://developer.swekee.com/2008/09/04/utilizando-xajax-05-en-php/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 02:00:58 +0000</pubDate>
		<dc:creator>david.alvaro</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[MYSQL]]></category>

		<guid isPermaLink="false">http://developer.swekee.com/?p=109</guid>
		<description><![CDATA[Hola tigrillo tu sabes que AJAX es ahora una técnica común al momento de crear un portal web, por eso te quiero mostrar como utilizar una de las tantas librerías AJAX para PHP que existen; Una de las tantas y mas fáciles de aprender es XAJAX, a continuación te mostrare como utilizarla:

Descarga las librerías XAJAX [...]]]></description>
			<content:encoded><![CDATA[<p>Hola tigrillo tu sabes que AJAX es ahora una técnica común al momento de crear un portal web, por eso te quiero mostrar como utilizar una de las tantas librerías <strong>AJAX</strong> para <strong>PHP</strong> que existen; Una de las tantas y mas fáciles de aprender es <strong>XAJAX</strong>, a continuación te mostrare como utilizarla:</p>
<ol>
<li>Descarga las librerías XAJAX 0.5 desde esta pagina <a href="http://xajaxproject.org/download.php" target="_blank">http://xajaxproject.org/download.php</a>.</li>
<li>Una vez que descargaste copia el contenido a una carpeta dentro de tu sitio web(en este ejemplo yo copie a una carpeta llamada xajax).</li>
<li>Luego empiezas a programar; En el ejemplo puedes observar que existen 3 archivos que tienen un mismo nombre en común es decir llevan la palabra “index”, esos archivos están relacionados entre si con la finalidad de poder ejecutar peticiones AJAX .</li>
</ol>
<p> <br />
<strong>OJO:</strong> Hemos clasificado 3 archivos para una sola pagina con la finalidad de mantener un orden al momento de programar y siguiendo la estructura de los ejemplos de la documentación de XAJAX que se asemeja a la programación en capas.</p>
<ul>
<li><strong>index.php</strong>, contendrá la fachada y los controles de la pagina.</li>
<li><strong>index.server.php</strong>, en este archivo se crean las funciones a utilizar</li>
<li><strong>index.common.php</strong>, se encarga de registrar e invocar las funciones creadas en index.server.php.</li>
</ul>
<p>y allí te va el código:</p>
<p><strong>INDEX.PHP</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index.common.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">//Haciendo referencia a las funciones registradas y que serán interpretadas como funciones javascript</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/********HACIENDO CONSULTA A LA TABLA Ciclo***********/</span>
<span style="color: #000088;">$db</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'root'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'db_alumnos'</span><span style="color: #339933;">,</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$rsCiclos</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'select codciclo,descripcion from ciclo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*****************************************************/</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Ejemplo XAJAX&lt;/title&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #666666; font-style: italic;">//indicamos al objeto xajax se encargue de generar el javascript de las funciones registradas por ejm: ListarCursosXCiclo</span>
<span style="color: #000088;">$xajax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">printJavascript</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'xajax/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/head&gt;
&lt;body&gt;
&lt;form name=&quot;frmPrueba&quot; id=&quot;frmPrueba&quot; method=&quot;post&quot;&gt;
	Ciclos : 
	&lt;select name=&quot;cboCiclos&quot; id=&quot;cboCiclos&quot; onChange=&quot;xajax_ListarCursosXCiclo(this.value);&quot;&gt;
		&lt;option value=&quot;&quot;&gt;--Seleccione--&lt;/option&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rsCiclos</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;option value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'codciclo'</span><span style="color: #009900;">&#93;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'descripcion'</span><span style="color: #009900;">&#93;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/option&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/select&gt;
	&lt;br&gt;&lt;br&gt;
	&lt;!--DIV donde se mostrara la respuesta AJAX--&gt;
	&lt;div id=&quot;divListado&quot;&gt;&lt;/div&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>
<strong>INDEX.SERVER.PHP</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #666666; font-style: italic;">//importando nuestras las referencias XAJAX</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;index.common.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//función que lista los Cursos segun el ciclo elegido</span>
<span style="color: #000000; font-weight: bold;">function</span> ListarCursosXCiclo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$codciclo</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
	<span style="color: #000088;">$db</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'root'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'db_alumnos'</span><span style="color: #339933;">,</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$objResponse</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> xajaxResponse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//instanciamos el objeto para la respuesta AJAX</span>
	<span style="color: #666666; font-style: italic;">//ISO-8859-1 significa que los caracteres latinos como la ñ y los acentos seran tomados en cuenta</span>
&nbsp;
	<span style="color: #000088;">$sql</span><span style="color: #339933;">=</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'select codcur,nomcur,desccur from curso where codciclo=%d'</span><span style="color: #339933;">,</span><span style="color: #000088;">$codciclo</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$rsCursos</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$cantRegistros</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rsCursos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$tabla</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//variable donde guardaremos la tabla HTML que luego se mostrara mediante AJAX</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cantRegistros</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// Si existen registros entonces armamos la cabecera de la tabla</span>
		<span style="color: #000088;">$tabla</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'&lt;table width=&quot;50%&quot; border=&quot;1&quot;&gt;
				  &lt;tr&gt;
					&lt;th scope=&quot;col&quot;&gt;CODIGO&lt;/th&gt;
					&lt;th scope=&quot;col&quot;&gt;CURSO&lt;/th&gt;
					&lt;th scope=&quot;col&quot;&gt;DESCRIPCION&lt;/th&gt;
				  &lt;/tr&gt;'</span><span style="color: #339933;">;</span>
	 	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rsCursos</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//recorriendo registro x registro y armando la tabla</span>
		 <span style="color: #000088;">$tabla</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">'&lt;tr&gt;
					&lt;td&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'codcur'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/td&gt;
					&lt;td&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nomcur'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/td&gt;
					&lt;td&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'desccur'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/td&gt;
				  &lt;/tr&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$tabla</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">'&lt;/table&gt;'</span><span style="color: #339933;">;</span>
	 <span style="color: #009900;">&#125;</span>
	 <span style="color: #666666; font-style: italic;">//asignando el contenido de la varabiale $tabla al div que esta en index.php</span>
	 <span style="color: #666666; font-style: italic;">//innerHTML reemplaza el contenido HTML por otro</span>
	 <span style="color: #000088;">$objResponse</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;divListado&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$tabla</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #666666; font-style: italic;">//mostramos un alert</span>
	 <span style="color: #000088;">$objResponse</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Este ciclo tiene &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$cantRegistros</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; cursos.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #b1b100;">return</span> <span style="color: #000088;">$objResponse</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//retornamos la respuesta AJAX</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$xajax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">processRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//procesando cualquier petición AJAX</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>
<strong>INDEX.COMMON.PHP</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//importando las librerias XAJAX</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;xajax/xajax_core/xajax.inc.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$xajax</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> xajax<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;index.server.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//asociamos la función creada en index.server.php al objeto XAJAX</span>
<span style="color: #000088;">$xajax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerFunction</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ListarCursosXCiclo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Ejecutando el ejemplo te deberia mostrar algo asi:<br />
<br />
<img src="http://farm4.static.flickr.com/3124/2829604758_542f98952c_m.jpg" alt="utilizando_xajax_en_php" width="240" height="155" /><br />
Si deseas puedes descargar el ejemplo desde <a href="http://www.box.net/shared/hf04pfc7iv" target="_blank">aqui</a>.<br />
<br />
Como puedes ver es simple el manejo de XAJAX 0.5, este es un ejemplo básico pronto espero publicar algo mas complejo.<br />
<br />
Mucha suerte !!</p>
]]></content:encoded>
			<wfw:commentRss>http://developer.swekee.com/2008/09/04/utilizando-xajax-05-en-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
