<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.5" -->
<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/"
	>

<channel>
	<title>Silici0 :: Blog</title>
	<link>http://www.rafaelcunha.com</link>
	<description>Php, JS, JQuery, Ajax e +++</description>
	<pubDate>Thu, 08 May 2008 13:32:54 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>
	<language>en</language>
			<item>
		<title>DHTML, DOM e JavaScript DOM não são a mesma coisa</title>
		<link>http://www.rafaelcunha.com/2008/05/05/dhtml-dom-e-javascript-dom-nao-sao-a-mesma-coisa/</link>
		<comments>http://www.rafaelcunha.com/2008/05/05/dhtml-dom-e-javascript-dom-nao-sao-a-mesma-coisa/#comments</comments>
		<pubDate>Mon, 05 May 2008 11:11:08 +0000</pubDate>
		<dc:creator>silici0</dc:creator>
		
		<category>Informatica</category>

		<category>JavaScript</category>

		<category>AJAX</category>

		<guid isPermaLink="false">http://www.rafaelcunha.com/2008/05/05/dhtml-dom-e-javascript-dom-nao-sao-a-mesma-coisa/</guid>
		<description><![CDATA[Bom vou falar um pouco sobre conceitos, logo para apresentar para vocês uma pouco o que realmente é DHTML ou Dynamic HTML e DOM, o que seria esse DOM que todo mundo fala? O conceito de DHTML é bem antigo, ja se usavam apartir do momento que lançaram o IE 4.0+, Netscape 7+, Mozilla e [...]]]></description>
			<content:encoded><![CDATA[<p>Bom vou falar um pouco sobre conceitos, logo para apresentar para vocês uma pouco o que realmente é DHTML ou Dynamic HTML e <a href="http://pt.wikipedia.org/wiki/DOM"  class="alinks_links" onclick="return alinks_click(this);" title="Document Object Model"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">DOM</a>, o que seria esse DOM que todo mundo fala? O conceito de DHTML é bem antigo, ja se usavam apartir do momento que lançaram o IE 4.0+, Netscape 7+, Mozilla e Firefox 1.0.</p>
<p>É a idéia de tornar a página dinâmica seria a possibilidade de transformar ou mudar estrutura da página sem o reload dela, mudar um título, cabeçalho, cor, esconder algo do usuário ou mostrar num passe de mágica, sem que ele espere pelo reload da página inteira novamente.</p>
<p>Mas o que tem a ver DOM e Javascript com tudo isso ? DOM significa Document Object Model (Modelo de Objetos de Documento) que seria a estrutura HTML. É basicamente uma arvóre de nós.</p>
<p>Exemplo:</p>
<div class="igBar"><span id="lhtml-2"><a href="#" onclick="javascript:showCodeTxt('html-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div id="html-2">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"xis"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"Y"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"H"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
No exemplo acima temos dentro da div XIS os seguintes nós XIS>Y>H . Dizendo como é nossa estrutura. A idéia do DHTML é de que com o JavaScript utilizando padronização (CSS, xHTML / HTML) podemos fazer mudanças nesta estrutura em tempo real para facilitar a vida do usuário, seja deixando um texto mais escuro, mudando uma img, abrindo e fechando caixas ou até mesmo com recursos mais avançados como o <a href="http://pt.wikipedia.org/wiki/AJAX_%28programa%C3%A7%C3%A3o%29"  class="alinks_links" onclick="return alinks_click(this);" title="Asynchronous JavaScript and XML"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">AJAX</a>.</p>
<p>Abraços e boa semana ; )
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rafaelcunha.com/2008/05/05/dhtml-dom-e-javascript-dom-nao-sao-a-mesma-coisa/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JSON Populando formulário</title>
		<link>http://www.rafaelcunha.com/2007/08/28/json-populando-formulario/</link>
		<comments>http://www.rafaelcunha.com/2007/08/28/json-populando-formulario/#comments</comments>
		<pubDate>Tue, 28 Aug 2007 02:25:29 +0000</pubDate>
		<dc:creator>silici0</dc:creator>
		
		<category>Informatica</category>

		<category>JavaScript</category>

		<category>AJAX</category>

		<category>Tutorial</category>

		<guid isPermaLink="false">http://rafaelcunha.com/2007/08/28/json-populando-formulario/</guid>
		<description><![CDATA[JSON, o que é ? É um acrônimo para JavaScript Object Notation, serve para que ? Serve para fazer intercâmbio de dados, mais utilizado no Ajax, atualmente utilizado para retorno de dados para o AJAX, com a necessidade de popular (retornar) dados para um formulário.
JSON que se lê djeissón, pode ser utilizado em diversas linguagens, [...]]]></description>
			<content:encoded><![CDATA[<p>JSON, o que é ? É um acrônimo para JavaScript Object Notation, serve para que ? Serve para fazer intercâmbio de dados, mais utilizado no Ajax, atualmente utilizado para retorno de dados para o AJAX, com a necessidade de popular (retornar) dados para um formulário.</p>
<p>JSON que se lê djeissón, pode ser utilizado em diversas linguagens, como php, c/c++, javascript, Java, Delphi, Perl, Python, Ruby, ColdFusion e muitas outras.</p>
<p>Imaginamos que ao clicar no botão alterar dados de uma lista, queremos trazer os dados da requisição do HTTP (Ajax) para colocalos no formulario. Para isso devemos retornar um dado do Ajax (arquivo da requisição) em JSON.</p>
<p>Para se encapsular dados para o Json no PHP basta o seguinte:</p>
<div class="igBar"><span id="lphp-5"><a href="#" onclick="javascript:showCodeTxt('php-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-5">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$array</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'a'</span>=&gt;<span style="color:#CC66CC;color:#800000;">1</span>,<span style="color:#FF0000;">'b'</span> =&gt; <span style="color:#CC66CC;color:#800000;">2</span>, <span style="color:#FF0000;">'c'</span> =&gt; <span style="color:#CC66CC;color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$res</span>=json_encode<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$array</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// retornando no res o seguinte:</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// {&quot;a&quot;:1, &quot;b&quot;:2, &quot;c&quot;:3 } </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Otimo, agora como devemos ler os dados do retorno no JavaScript? Essa é parte mais fácil, para converter dados do texto <a href="http://pt.wikipedia.org/wiki/JSON"  class="alinks_links" onclick="return alinks_click(this);" title="JavaScript Object Notation"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">JSON</a> para objetos (variavel do JS) basta usar a função eval();</p>
<div class="igBar"><span id="ljavascript-6"><a href="#" onclick="javascript:showCodeTxt('javascript-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-6">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// resposta é o $res do PHP, retorno dos dados</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">eval</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"var arr = "</span>+resposta<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// Agora temos uma array de dados em javascript</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// exemplo arr.a = 1</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// exemplo arr.b = 2</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// exemplo arr.c = 3 </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Agora basta popular o formulário (inputs, text area e afins) com <a href="http://pt.wikipedia.org/wiki/DOM"  class="alinks_links" onclick="return alinks_click(this);" title="Document Object Model"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">DOM</a> HTML. Pronto você aprendeu como JSON trabalha, o que é e como utilizar, agora basta utilizar suas ideias em conjunto ao <a href="http://pt.wikipedia.org/wiki/AJAX_%28programa%C3%A7%C3%A3o%29"  class="alinks_links" onclick="return alinks_click(this);" title="Asynchronous JavaScript and XML"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">Ajax</a> e construir maravilhas.
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rafaelcunha.com/2007/08/28/json-populando-formulario/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JQuery - Ajax métodos</title>
		<link>http://www.rafaelcunha.com/2007/08/26/jquery-ajax-metodos/</link>
		<comments>http://www.rafaelcunha.com/2007/08/26/jquery-ajax-metodos/#comments</comments>
		<pubDate>Sun, 26 Aug 2007 23:42:06 +0000</pubDate>
		<dc:creator>silici0</dc:creator>
		
		<category>JQuery</category>

		<category>AJAX</category>

		<guid isPermaLink="false">http://rafaelcunha.com/2007/08/26/jquery-ajax-metodos/</guid>
		<description><![CDATA[Lista de métodos do JQuery para se usar o Ajax, como eu utilizei alguns vou falar sobre os outros, uma breve descrição para utilização, como usar vide o manual:
$.ajax( propriedades )
Abre uma página remota utilizando o requeste de HTTP. Pode ser utilizado com envio de POST, GET e leitura de scripts JS e muito mais.
$.ajaxSetup [...]]]></description>
			<content:encoded><![CDATA[<p>Lista de métodos do <a href="http://jquery.com"  class="alinks_links" onclick="return alinks_click(this);" title="JavaScript Framework"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">JQuery</a> para se usar o <a href="http://pt.wikipedia.org/wiki/AJAX_%28programa%C3%A7%C3%A3o%29"  class="alinks_links" onclick="return alinks_click(this);" title="Asynchronous JavaScript and XML"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">Ajax</a>, como eu utilizei alguns vou falar sobre os outros, uma breve descrição para utilização, como usar vide o <a title="Documentação do Jquery" target="_blank" href="http://docs.jquery.com">manual</a>:</p>
<p>$.ajax( propriedades )<br />
Abre uma página remota utilizando o requeste de HTTP. Pode ser utilizado com envio de POST, GET e leitura de scripts JS e muito mais.</p>
<p>$.ajaxSetup ( propriedades )<br />
Seta todas propriedades GLOBAL do request do ajax.</p>
<p>$.ajaxTimeout( time )<br />
Seta o tempo no qual ocorrerá a espera antes da execução da requisição do ajax.</p>
<p>$.get( <a href="http://pt.wikipedia.org/wiki/URL"  class="alinks_links" onclick="return alinks_click(this);" title="Uniform Resource Locator"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">url</a>, parametros, retorno da chamada )<br />
Lê uma página remota enviando os dados via GET, mandando URL, parametros são os dados do GET e possibilidade de fazer controle de error no retorno.</p>
<p>$.getJSON( url, parametros, retorno da chamada )<br />
Lê dados <a href="http://pt.wikipedia.org/wiki/JSON"  class="alinks_links" onclick="return alinks_click(this);" title="JavaScript Object Notation"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">JSON</a> utilizando requisição HTTP.</p>
<p>$.getScript( url, retorno da chamada )<br />
Lê e executa um script JavaScript utilizando requisição HTTP GET.</p>
<p>$.post( ? vide outros topicos ?)</p>
<p>ajaxComplete( retorno )<br />
Função que será executada após o ajax ter completado.</p>
<p>ajaxError( retorno )<br />
Função que será executada caso a requisição falhe.</p>
<p>ajaxSend( retorno )<br />
Função que será executada antes da requisição do ajax ser enviado.</p>
<p>ajaxStop( retorno )<br />
Função que será executada após todas requisições ajax terminarem.</p>
<p>ajaxSucess( retorno )<br />
Função que será executada após todas requisições ajax forem bem sucedidas.</p>
<p>load( url, parametros, retorno )<br />
Lê um arquivo HTML e injeta isto ao <a href="http://pt.wikipedia.org/wiki/DOM"  class="alinks_links" onclick="return alinks_click(this);" title="Document Object Model"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">DOM</a>.</p>
<p>Então estão ae todas ou pelos menos algumas possibilidades que o JQuery lhe da para trabalhar com AJAX, espero que ajude a organizar um pouco as idéias e melhorar na produção, ganhar um pouco em código, pois pelo que eu vi, em vez de usarem os métodos prontos o pessoal tem usado DOM e as vezes retornado problemas diante do I.E.
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rafaelcunha.com/2007/08/26/jquery-ajax-metodos/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Entenda o que é AJAX !</title>
		<link>http://www.rafaelcunha.com/2007/06/15/entenda-o-que-e-ajax/</link>
		<comments>http://www.rafaelcunha.com/2007/06/15/entenda-o-que-e-ajax/#comments</comments>
		<pubDate>Fri, 15 Jun 2007 12:05:18 +0000</pubDate>
		<dc:creator>silici0</dc:creator>
		
		<category>Informatica</category>

		<category>Trabalho</category>

		<category>JavaScript</category>

		<category>AJAX</category>

		<guid isPermaLink="false">http://rafaelcunha.com/2007/06/15/entenda-o-que-e-ajax/</guid>
		<description><![CDATA[Muito comum eu ver por ai ou me perguntarem se eu tenho função X em AJAX ou como se faz coisa Y em AJAX, sendo que muitas vezes o X e/ou Y estão longe de ser uma sistemática de AJAX, por isso hoje vou escrever esse texto para finalmente tirar todas dúvidas sobre o que [...]]]></description>
			<content:encoded><![CDATA[<p>Muito comum eu ver por ai ou me perguntarem se eu tenho função X em <a href="http://pt.wikipedia.org/wiki/AJAX_%28programa%C3%A7%C3%A3o%29"  class="alinks_links" onclick="return alinks_click(this);" title="Asynchronous JavaScript and XML"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">AJAX</a> ou como se faz coisa Y em AJAX, sendo que muitas vezes o X e/ou Y estão longe de ser uma sistemática de AJAX, por isso hoje vou escrever esse texto para finalmente tirar todas dúvidas sobre o que é ou não esse tal de AJAX.</p>
<p>AJAX é a abreviação do <strong>Asynchronous Javascript And <a href="http://pt.wikipedia.org/wiki/XML"  class="alinks_links" onclick="return alinks_click(this);" title="eXtensible Markup Language"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">XML</a></strong> assíncrono de  JavaScript e XML (não necessário sendo XML), mas esse assincrono por ae o que é?  É a idéia de 'liberdade',  a base de  você fazer uma  requisição ao servidor e esperar, porém enquanto você espera você esta livre para fazer outras coisas. Exemplo: Se você requisitar se um usuário é valido ou não você pode enquanto isso, colocar uma img de loading na tela enquanto não vem a 'reposta'. Assim que a resposta chegar você toma as devidas decisões.</p>
<p><a target="_blank" href="http://www.imagereward.com/Imageviewer.aspx?image=NDQyMjc%3d"></p>
<div style="text-align: center"><img border="0" src="http://www.imagereward.com/images2/public/2007/166/7//ajax-perth-australia-web-development_s.gif" /></div>
<p></a>Hmmm... esta començando e entender? Então ja de base nós temos em mente que todo AJAX é um requisição ao servidor, sem tempo de resposta, (geralmente é rápido) e na qual podemos fazer ações enquanto não chega a resposta.</p>
<p>E o XML, seria a idéia de que toda resposta da requisição deveria ter, porém nos podemos trazer tranquilamente respostas em outros formatos conteúdo HTML, documento em XML, simplesmente algum 'texto' ou notação de objeto de JavaScript (famoso <a href="http://pt.wikipedia.org/wiki/JSON"  class="alinks_links" onclick="return alinks_click(this);" title="JavaScript Object Notation"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">JSON</a>). Então quando receber essa requisição, trabalhar com esses dados. Todos esses tipos de resposta de requisição referen-se a tecnologia ou método AJAX.</p>
<p><a target="_blank" href="http://www.imagereward.com/Imageviewer.aspx?image=NDQyMjg%3d"></p>
<div style="text-align: center"><img border="0" src="http://www.imagereward.com/images/public/2007/166/7//interaction_s.jpg" /></div>
<p></a>Apartir então da reposta você pode atualizar ou modificar o conteúdo da 'página' com o Modelo de Objeto do Documento (famoso <a href="http://pt.wikipedia.org/wiki/DOM"  class="alinks_links" onclick="return alinks_click(this);" title="Document Object Model"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">DOM</a>).</p>
<p>Com as imagens acima você ver 'desenhado' como é a idéia de requisição e resposta, com tudo isso você tem a vantagem de ter páginas mais dinamicas afim de melhorar o desempenho em relação ao usuário. Dúvidas? Sugestões? So comentar.
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rafaelcunha.com/2007/06/15/entenda-o-que-e-ajax/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ajax com JQuery : Download</title>
		<link>http://www.rafaelcunha.com/2007/05/20/ajax-com-jquery-download/</link>
		<comments>http://www.rafaelcunha.com/2007/05/20/ajax-com-jquery-download/#comments</comments>
		<pubDate>Sun, 20 May 2007 20:07:00 +0000</pubDate>
		<dc:creator>silici0</dc:creator>
		
		<category>Informatica</category>

		<category>php</category>

		<category>JQuery</category>

		<category>AJAX</category>

		<guid isPermaLink="false">http://rafaelcunha.com/2007/05/20/ajax-com-jquery-download/</guid>
		<description><![CDATA[A pedidos estou disponibilizando o download dos arquivos do post : Ajax + Jquery = Facilidade para que possam identificar melhor os script escritos no tutorial. Basta clicar no link abaixo para fazer o download dos arquivos.
AJQDownload
Dúvidas é comentar. Abraços e boa diversão.

]]></description>
			<content:encoded><![CDATA[<p>A pedidos estou disponibilizando o download dos arquivos do post :<a href="http://rafaelcunha.com/2007/04/27/ajax-jquery-facilidade/"> Ajax + Jquery = Facilidade </a>para que possam identificar melhor os script escritos no tutorial. Basta clicar no link abaixo para fazer o download dos arquivos.<br />
<a href="http://www.rafaelcunha.com/testes/AJAX com JQuery.php.zip"  class="alinks_links" onclick="return alinks_click(this);" title="Download dos arquivos do tutorial"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">AJQDownload</a><br />
Dúvidas é comentar. Abraços e boa diversão.
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rafaelcunha.com/2007/05/20/ajax-com-jquery-download/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Populando combobox com JQuery ( Ajax )</title>
		<link>http://www.rafaelcunha.com/2007/05/10/populando-combobox-com-jquery-ajax/</link>
		<comments>http://www.rafaelcunha.com/2007/05/10/populando-combobox-com-jquery-ajax/#comments</comments>
		<pubDate>Thu, 10 May 2007 12:22:48 +0000</pubDate>
		<dc:creator>silici0</dc:creator>
		
		<category>Informatica</category>

		<category>php</category>

		<category>JavaScript</category>

		<category>JQuery</category>

		<category>AJAX</category>

		<guid isPermaLink="false">http://rafaelcunha.com/2007/05/10/populando-combobox-com-jquery-ajax/</guid>
		<description><![CDATA[Mais uma vez vamos a um tutorialzinho de como popular um combobox apartir de outra seleção, a idéia aqui é a tão famosa Seleciona o estado e retorna todas as cidades em outro combobox sem dar reload na página, para isso vamos economizar bastante código e tempo utilizando o framework do JQuery.
Primeiro vamos ter uma [...]]]></description>
			<content:encoded><![CDATA[<p>Mais uma vez vamos a um tutorialzinho de como popular um combobox apartir de outra seleção, a idéia aqui é a tão famosa Seleciona o estado e retorna todas as cidades em outro combobox sem dar reload na página, para isso vamos economizar bastante código e tempo utilizando o framework do <a href="http://jquery.com"  class="alinks_links" onclick="return alinks_click(this);" title="JavaScript Framework"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">JQuery</a>.</p>
<p>Primeiro vamos ter uma tabela com todas as cidades brasileiras... são 5564 (pelo que eu achei) e é um pouco dificil escreever tudo isso no input para dentro de um banco de dados, por isso segue o link para pegar esse sql pronto : <a target="_blank" href="http://felipesantiago.com/scripts/cidades/cidades.sql">Todas cidades brasileiras em SQL</a>.</p>
<p>Depois de criar vamos criar o form, ai como isso vai ficar grande, vou economizar codigo colocando em umas linhas, mas deem preferencia para linhas organizadas (hehehe):</p>
<div class="igBar"><span id="lhtml-15"><a href="#" onclick="javascript:showCodeTxt('html-15'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div id="html-15">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">&lt;form</span></a> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"frmAjax"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/label.html"><span style="color: #000000; font-weight: bold;">&lt;label</span></a> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">"listEstados"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span> Estado:<span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/select.html"><span style="color: #000000; font-weight: bold;">&lt;select</span></a> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"listEstados"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"0"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span> Selecione o estado&gt;&gt;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"ac"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Acre<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"al"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Alagoas<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"ap"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Amapa<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"am"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Amazonas<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"ba"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Bahia<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"ce"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Ceara<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"df"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Distrito Federal<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"es"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Espirito Santo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"go"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Goias<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"ma"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Maranhao<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"mt"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Mato Grosso<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"ms"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Mato Grosso do Sul<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"mg"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Minhas Gerais<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"pa"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Para<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"pb"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Paraiba<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"pr"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Parana<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"pe"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Pernambuco<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"pi"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Piaui<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"rj"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Rio de Janeiro<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"rn"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Rio Grande do Norte<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"rs"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Rio Grande do Sul<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"ro"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Rondonia<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"rr"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Roraima<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"sc"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Santa Catarina<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"sp"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Sao Paulo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"se"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Sergipe<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"to"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Tocantins<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/select&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/label.html"><span style="color: #000000; font-weight: bold;">&lt;label</span></a> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">"listCidades"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Cidade:<span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/select.html"><span style="color: #000000; font-weight: bold;">&lt;select</span></a> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"listCidades"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"opcoes"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"0"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>-- Primeiro selecione o estado --<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/select&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Agora vamos ao uso do Jquery, primeiro chamamos o framework, caso você não esteja acustumado, ou nunca viu como utilizar ele, basta pegar ele e chamar ele na página, COMO?</p>
<div class="igBar"><span id="lhtml-16"><a href="#" onclick="javascript:showCodeTxt('html-16'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div id="html-16">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"text/javascript"</span> xsrc=<span style="color: #ff0000;">"js/jquery.js"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Agora vamos realmente ao código que interessa. Primeiramente eu digo que irei chamar um método quando o botão de 'listEstados' for 'mudado':</p>
<div class="igBar"><span id="ljavascript-17"><a href="#" onclick="javascript:showCodeTxt('javascript-17'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-17">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"select[@name=listEstados]"</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">change</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Depois então que eu mudar ou melhor selecionar um Estado, vou mudar a opção das cidades para Procurando, afim de informar o usuário, que estou procurando os dados para ele:</p>
<div class="igBar"><span id="ljavascript-18"><a href="#" onclick="javascript:showCodeTxt('javascript-18'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-18">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'select[@name=listCidades]'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Procurando :::::::'</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Logo em seguida chamo o <a href="http://pt.wikipedia.org/wiki/AJAX_%28programa%C3%A7%C3%A3o%29"  class="alinks_links" onclick="return alinks_click(this);" title="Asynchronous JavaScript and XML"  style="padding-right: 13px; background: url(http://rafaelcunha.com/WordPress/wp-content/plugins/alinks/images/external.png) center right no-repeat;" rel="external">AJAX</a>, envio um POST para ele do estado que selecionei e com isso digo o arquivo que irei passar esse POST e recebo uma resposta:<br />
Enviando para arquivo : buscacidade.php<br />
Enviando a variavel estado : 'valordo form, estado que eu selecionar'<br />
Então recebo uma reposta chamada 'resposta';</p>
<div class="igBar"><span id="ljavascript-19"><a href="#" onclick="javascript:showCodeTxt('javascript-19'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-19">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$.<span style="color: #006600;">post</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'buscacidade.php'</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span> estado : $<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">val</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#125;</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>resposta<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Apos a Resposta basta eu mudar todo a listagem de cidade que eu recebi como resposta:</p>
<div class="igBar"><span id="ljavascript-20"><a href="#" onclick="javascript:showCodeTxt('javascript-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-20">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'select[@name=listCidades]'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span>resposta<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>O arquivo buscacidade.php se pareçe com isso aqui :</p>
<div class="igBar"><span id="lphp-21"><a href="#" onclick="javascript:showCodeTxt('php-21'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-21">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$_POST</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'estado'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$res</span>=<a href="http://www.php.net/mysql_query"><span style="color:#000066;">mysql_query</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'SELECT * FROM cidades WHERE uf = <span style="color:#000099; font-weight:bold;">\'</span>'</span>.<span style="color:#0000FF;">$_POST</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'estado'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#FF0000;">'<span style="color:#000099; font-weight:bold;">\'</span>'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$cont</span>=<span style="color:#CC66CC;color:#800000;">0</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">while</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ok</span>=<a href="http://www.php.net/mysql_fetch_array"><span style="color:#000066;">mysql_fetch_array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$res</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$vai</span>=crossUrlDecode<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ok</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'municipio'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">''</span>.<span style="color:#0000FF;">$vai</span>.<span style="color:#FF0000;">''</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$cont</span>++;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#616100;">else</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">'Erro no envio dos dados'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>O código por completo, como ficou ?</p>
<div class="igBar"><span id="ljavascript-22"><a href="#" onclick="javascript:showCodeTxt('javascript-22'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-22">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">ready</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"select[@name=listEstados]"</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">change</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'select[@name=listCidades]'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'&lt;option value=&quot;sda&quot;&gt;Procurando :::::::&lt;/option&gt;'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$.<span style="color: #006600;">post</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'buscacidade.php'</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span> estado : $<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">val</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#125;</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>resposta<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'select[@name=listCidades]'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span>resposta<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Para ver esse código todo em funcionamento clique <a target="_blank" href="http://www.rafaelcunha.com/testes/estado/">AQUI</a>.</p>
<p>É isso ae, super simples e funcional; alem de ser rápido de se iplementar, acho que meu maior tempo gasto foi escreevendo esse tutorial, demorou 2 dias (??), hehehe. Dúvidas? Sugestões? So comentar...
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rafaelcunha.com/2007/05/10/populando-combobox-com-jquery-ajax/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
