<?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>Blog de desenvolvimento da Milfont Consulting, Client e Server-side &#187; XMLHttpRequest</title>
	<atom:link href="http://www.milfont.org/tech/category/web-development/xmlhttprequest/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.milfont.org/tech</link>
	<description>Blog da Comunidade Milfont Consulting, uma empresa especializada em desenvolvimento Web, principalmente Javascript, node.js e muito Javascript.</description>
	<lastBuildDate>Thu, 26 Jan 2012 11:30:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Problema de Entity Body incluso em HTTP DELETE Request</title>
		<link>http://www.milfont.org/tech/2011/04/04/problema-de-entity-body-incluso-em-http-delete-request/</link>
		<comments>http://www.milfont.org/tech/2011/04/04/problema-de-entity-body-incluso-em-http-delete-request/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 14:34:26 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Ext]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Jquery]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[HTTP]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/?p=1218</guid>
		<description><![CDATA[Problema que detectei em algumas applicações que estamos desenvolvendo com Extjs+Jquery: Na máquina de entrega o request do tipo DELETE funcionava tranquilamente, na máquina de produção hospedada no Rackspace quebrava. Como a máquina de entrega estava dentro da nossa rede, suspeitei logo da conexão, firewall e essas coisas. O @rponte me deu a dica desse [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript">
			<!-- 
				tweetmeme_url = "http://www.milfont.org/tech/2011/04/04/problema-de-entity-body-incluso-em-http-delete-request/";
				tweetmeme_source = "tweetmeme";
				tweetmeme_style = "";
				
			//-->
			</script>
                        <script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div></div><p>Problema que detectei em algumas applicações que estamos desenvolvendo com Extjs+Jquery: Na máquina de entrega o request do tipo DELETE funcionava tranquilamente, na máquina de produção hospedada no <a href="http://www.rackspace.com/index.php">Rackspace</a> quebrava. Como a máquina de entrega estava dentro da nossa rede, suspeitei logo da conexão, firewall e essas coisas.</p>
<p>O <a href="http://twitter.com/#!/rponte">@rponte</a> me deu a <a href="http://stackoverflow.com/questions/299628/is-an-entity-body-allowed-for-an-http-delete-request">dica desse post</a> que ele encontrou com o mesmo tipo de problema. Nunca tinha percebido que a <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html">spec HTTP nem proibe e nem recomenda</a> corpo em DELETE. Não faz muito sentido enviar corpo realmente em DELETE, mas até aí tudo bem.</p>
<p>Para completar, o Extjs já previa esse problema e o <a href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.JsonWriter">JsonWriter</a> possui uma propriedade chamada &#8220;encodeDelete&#8221; para você explicitamente definir que não quer corpo em DELETE, por default já vem assim.</p>
<p>No console do firebug eu utilizava o <a href="http://api.jquery.com/jQuery.ajax/">$.ajax</a> e o <a href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.Ajax">Ext.Ajax</a> diretamente com a mesma url para enviar DELETE e funcionava, mas na aplicação não funcionava. Conversando com o pessoal da rede eles me disseram que trocaram o firewall recentemente e observando o log a chamada sequer passava por lá, ou seja, provavelmente ele já rejeita qualquer conexão DELETE com body.</p>
<p>Fui analizar o código do Extjs e ele enviava um body, a diferença é que era vazio, mas ia. Fiz um hack para destruir qualquer parametro quando a conexão fosse para o DELETE e consertou, como pode ver no código abaixo:</p>
<p><script src="https://gist.github.com/885190.js"> </script><br />
<a href="https://gist.github.com/raw/885190/c742a8aa8c1b7d1afce4a8a17ea888f22b9171fb/hack.httpproxy.extjs.3x.js">Link caso não consiga ver no seu reader.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2011/04/04/problema-de-entity-body-incluso-em-http-delete-request/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introdução ao Ext</title>
		<link>http://www.milfont.org/tech/2009/06/29/introducao-ao-ext/</link>
		<comments>http://www.milfont.org/tech/2009/06/29/introducao-ao-ext/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 13:38:32 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Ext]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[web2.0]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>
		<category><![CDATA[ECMAScript]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Orientação a Objetos]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/?p=24</guid>
		<description><![CDATA[Eu trabalho com Extjs desde que ele era uma extensão para o YUI, ainda hoje há aplicação no ar usando essa antiga tecnologia [por problema causado por algum idiota, você provavelmente será redirecionado para outro site do governo, dá uma olhada no canto esquerdo superior e clique em "IR PARA A SEPLAG"]. Para ver o [...]]]></description>
			<content:encoded><![CDATA[<p>Eu trabalho com <a href="http://www.extjs.com/products/extjs/">Extjs</a> desde que ele era uma extensão para o <a href="http://developer.yahoo.com/yui/">YUI</a>, ainda hoje <a href="http://www.seplag.ce.gov.br/seplag/categoria2/diario-oficial">há aplicação no ar</a> usando essa antiga tecnologia [por problema <a href="http://www.milfont.org/tech/2009/03/25/como-simular-trabalho-no-estado/">causado por algum idiota</a>, você provavelmente será redirecionado para outro site do governo, dá uma olhada no canto esquerdo superior e clique em "<strong>IR PARA A SEPLAG</strong>"]. Para ver o Extjs no tempo que ele se chamava ext-yui, vá no link de pesquisa avançada, preencha o input descrição em &#8220;dados da matéria&#8221; com &#8220;secretaria de cultura&#8221; por exemplo e clique no botão pesquisar.</p>
<p>Esse tutorial tem o objetivo de preparar o conhecimento para outros posts que estou escrevendo e achei necessário uma introdução apenas nos conceitos do Extjs para não confundir com as tecnologias que uso em conjunto como <a href="http://www.milfont.org/tech/tag/dwr/">DWR</a> ou no modelo <a href="http://www.milfont.org/tech/tag/rest/">REST</a> com o <a href="http://www.milfont.org/tech/tag/rails/">RubyOnRails</a>.</p>
<p>O Extjs é um <a href="http://www.milfont.org/tech/2007/10/11/frameworks-ajax/">framework javascript de propósito geral</a>, ou seja, tem um conjunto de funcionalidades que tratam <a href="http://www.milfont.org/tech/tag/ajax/">Ajax</a>, um conjunto de Widgets bem elaborados [componentes visuais como Grid e TabPanel], manipulação de DOM [Document Object Model] e BOM [Browser Object Model], tratamento de eventos, animações como Fade In e Fade Out, parser de <a href="http://www.milfont.org/tech/2007/11/04/o-que-e-json/">JSON</a>, entre outras coisas. Seus componentes são construídos com técnicas modernas de<a href="http://www.milfont.org/tech/2008/01/05/heranca-no-javascript/"> orientação</a> a <a href="http://www.milfont.org/tech/2007/10/01/overloading-e-overriding-no-javascript/">objetos</a> no javascript e manipulação de <a href="http://www.milfont.org/tech/2007/10/08/script-tag/">Scripttag</a> para recursos remotos que não suportam Ajax.</p>
<h2>Preparação</h2>
<p>Após <a href="http://www.extjs.com/products/extjs/download.php">baixar e descompactar</a> o framework [estou trabalhando na versão 2.x que é estável nessa data], recomendo que deixa a disposição das pastas conforme se encontra e coloque no seu projeto de forma que seja acessível via web, já vem com documentação e exemplos que você deve e vai usar durante o desenvolvimento. Temos a <a href="http://www.extjs.com/products/extjs/build/">opção de montar o Extjs</a> [marcando a opção "<em>Make build available via CacheFly</em>" ] no <a href="http://cachefly.com/">CacheFly</a> como um servidor <a href="http://en.wikipedia.org/wiki/Content_Delivery_Network">CDN</a> para <a href="http://www.milfont.org/tech/2007/10/10/otimizando-wordpress-com-yslow/">otimizar o tráfego</a> de sua aplicação principalmente se ela será disponibilizada na internet e não apenas na intranet.</p>
<p>É necessário importar o CSS global, o adapter e o Javascript global conforme mostrado abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/javascripts/ext-2.2.1/resources/css/ext-all.css&quot; /&gt;
&lt;script src=&quot;/javascripts/ext-2.2.1/adapter/ext/ext-base.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/javascripts/ext-2.2.1/ext-all.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>Pode usar outros temas para o Extjs, estarão na pasta &#8220;<em>resources/css</em>&#8220;, assim como podemos internacionalizar os componentes com arquivos que se encontram em &#8220;<em>build/locale</em>&#8220;. Exemplo com o tema &#8220;Gray&#8221; e <a href="http://en.wikipedia.org/wiki/Internationalization_and_localization">i18n</a> em português do Brasil:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/javascripts/ext-2.2.1/resources/css/ext-all.css&quot; /&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/javascripts/ext-2.2.1/resources/css/xtheme-gray.css&quot;&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/ext-2.2.1/adapter/ext/ext-base.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/ext-2.2.1/ext-all.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/ext-2.2.1/build/locale/ext-lang-pt_BR-min.js&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>Internacionalização é algo pensado no Extjs de forma a facilitar a criação de arquivos de linguagem aproveitando a estrutura da linguagem [dinâmica e fracamente tipada], todas as propriedades de mensagens e textos são públicas para facilitar a reescrita como mostrado abaixo na i18n do componente de DataPicker:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>Ext.<span style="color: #660066;">DatePicker</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   Ext.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>Ext.<span style="color: #660066;">DatePicker</span>.<span style="color: #660066;">prototype</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
      todayText         <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Hoje&quot;</span><span style="color: #339933;">,</span>
      minText           <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Esta data &amp;eacute; anterior a menor data&quot;</span><span style="color: #339933;">,</span>
      maxText           <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Esta data &amp;eacute; posterior a maior data&quot;</span><span style="color: #339933;">,</span>
      disabledDaysText  <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span>
      disabledDatesText <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span>
      monthNames        <span style="color: #339933;">:</span> Date.<span style="color: #660066;">monthNames</span><span style="color: #339933;">,</span>
      dayNames          <span style="color: #339933;">:</span> Date.<span style="color: #660066;">dayNames</span><span style="color: #339933;">,</span>
      nextText          <span style="color: #339933;">:</span> <span style="color: #3366CC;">'Pr&amp;oacute;ximo M&amp;ecirc;s (Control+Direita)'</span><span style="color: #339933;">,</span>
      prevText          <span style="color: #339933;">:</span> <span style="color: #3366CC;">'M&amp;ecirc;s Anterior (Control+Esquerda)'</span><span style="color: #339933;">,</span>
      monthYearText     <span style="color: #339933;">:</span> <span style="color: #3366CC;">'Escolha um M&amp;ecirc;s (Control+Cima/Baixo para mover entre os anos)'</span><span style="color: #339933;">,</span>
      todayTip          <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;{0} (Espa&amp;ccedil;o)&quot;</span><span style="color: #339933;">,</span>
      format            <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;d/m/Y&quot;</span><span style="color: #339933;">,</span>
      okText            <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&amp;#160;OK&amp;#160;&quot;</span><span style="color: #339933;">,</span>
      cancelText        <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Cancelar&quot;</span><span style="color: #339933;">,</span>
      startDay          <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span>
   <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Se você usar o CacheFly gerado pela página do Extjs, ele incluir o adapter e o global em um mesmo arquivo, vai ser algo como:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://extjs.cachefly.net/ext-2.2.1/resources/css/ext-all.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://extjs.cachefly.net/ext-2.2.1/resources/css/xtheme-gray.css&quot;&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://extjs.cachefly.net/builds/ext-cdn-771.js&quot;&gt;&lt;/script&gt;</pre></div></div>

<h2>Adapter</h2>
<p>Quando o Extjs passou a ser um framework independente do YUI, passou a adotar outros frameworks como base para funções básicas de manipulação de DOM e Ajax, hoje suporta trabalhar em conjunto com YUI, JQuery, Prototype e totalmente independente. Se o projeto já tem Jquery ou outro framework que trabalha com o Extjs, a utilização dos dois é muito fácil e indicada, principalmente para usar os widgets que são provavelmente os mais poderosos hoje em dia em um framework opensource.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">//Exemplos de adapters permitidos
&lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/ext-2.2.1/adapter/ext/ext-base.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/ext-2.2.1/adapter/jquery/ext-jquery-adapter.js&quot;&gt;&lt;/script&gt;</pre></div></div>

<h2>Widgets</h2>
<p>O principal apelo do Extjs que conquista os desenvolvedores é o layout bem trabalhado dos componentes visuais que são de fácil parametrização. Basicamente todos os componentes funcionam da mesma forma, você o instancia passando um <a href="http://www.milfont.org/tech/2007/11/04/o-que-e-json/">objeto literal</a> de configuração com mostrado abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//Exemplo do grid</span>
<span style="color: #003366; font-weight: bold;">var</span> grid  <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">GridPanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
autoShow<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span><span style="color: #CC0000;">750</span><span style="color: #339933;">,</span>height<span style="color: #339933;">:</span><span style="color: #CC0000;">250</span> <span style="color: #006600; font-style: italic;">//mais parametros </span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//Exemplo de uma Window</span>
<span style="color: #003366; font-weight: bold;">var</span> window <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">Window</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
autoShow<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span><span style="color: #CC0000;">750</span><span style="color: #339933;">,</span>height<span style="color: #339933;">:</span><span style="color: #CC0000;">250</span> <span style="color: #006600; font-style: italic;">//mais parametros </span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//Exemplo de um Painel</span>
<span style="color: #003366; font-weight: bold;">var</span> panel <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">Panel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
autoShow<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span><span style="color: #CC0000;">750</span><span style="color: #339933;">,</span>height<span style="color: #339933;">:</span><span style="color: #CC0000;">250</span> <span style="color: #006600; font-style: italic;">//mais parametros </span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Vamos usar o GRID para exemplificar como trabalhamos com o Extjs, o mesmo comportamente se repete em todos os componentes.<br />
A <a href="http://www.extjs.com/deploy/dev/docs/">documentação do Extjs</a> é muito bem feita e praticamente vai ser a única coisa que você vai precisar depois de entender como os componentes são formados, afinal não vale a pena decorar todas as propriedades de todos os componentes, concentre-se apenas em entender os conceitos.</p>
<p>A GRID é o Widget mais famoso desse framework e é formado basicamente por um objeto &#8220;<strong>Ext.data.Store</strong>&#8221; [que é a fonte de dados da GRID] e um objeto &#8220;<strong>Ext.grid.ColumnModel</strong>&#8221; [que é a definição das colunas], como mostrado abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> grid  <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">GridPanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    autoShow<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span><span style="color: #CC0000;">750</span><span style="color: #339933;">,</span>height<span style="color: #339933;">:</span><span style="color: #CC0000;">250</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//parametros de configuração de layout</span>
    cm<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">ColumnModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #006600; font-style: italic;">/*configuração*/</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    store<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//Ou especialização de um Store</span>
    sm<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">RowSelectionModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>singleSelect<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//ou outra especialização de um AbstractSelectionModel</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>O objeto ColumnModel é a definição de colunas do Grid, possui propriedades para definição de layout como largura e altura, título da coluna como vai ser exibida e formatação do texto:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> colModel <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">ColumnModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
    <span style="color: #009900;">&#123;</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Ticker&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">60</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Company Name&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">150</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Market Cap.&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;$ Sales&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> renderer<span style="color: #339933;">:</span> money<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Employees&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> resizable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>A propriedade cm [ColumnModel] pode ser também substituída pela propriedade &#8220;columns&#8221; que funciona como um &#8220;alias&#8221;, dessa forma o Grid cria automaticamente um objeto ColumnModel:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> grid <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">GridPanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    columns<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span>id<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span>header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Nome&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">120</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Caso haja necessidade de formatar o conteúdo da célula, você pode usar uma função como &#8220;renderer&#8221; para tratar esse conteúdo:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> grid <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">GridPanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    columns<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span>id<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span>header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Nome&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">120</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span>header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Criado em&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">135</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> renderer<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> Date.<span style="color: #660066;">parseDate</span><span style="color: #009900;">&#40;</span>value<span style="color: #339933;">,</span> <span style="color: #3366CC;">'Y-m-d<span style="color: #000099; font-weight: bold;">\\</span>TH:i:s<span style="color: #000099; font-weight: bold;">\\</span>Z'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">format</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'d/m/Y H:i:s'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #006600; font-style: italic;">//2009-06-14T12:51:07Z</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'created_at'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>A propriedade &#8220;<strong>store</strong>&#8221; da GRID é uma especialização do componente &#8220;<strong>Ext.data.Store</strong>&#8221; que é formado basicamente por um &#8220;<strong>proxy</strong>&#8221; e um &#8220;<strong>reader</strong>&#8220;:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> store <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    proxy<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">DataProxy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//ou uma especialização</span>
    reader<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">DataReader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">//ou uma especialização</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>O &#8220;<strong>proxy</strong>&#8221; é o componente que obterá os dados e o &#8220;<strong>reader</strong>&#8221; o componente que fará a leitura desses dados para um formato comum a todos os componentes do Extjs na forma de um objeto denominado &#8220;<strong>Ext.data.Record</strong>&#8220;. O objeto &#8220;Record&#8221; representa um registro de dados e é usado seja para GRID, para um Form ou qualquer componente que trabalhe com dados editáveis.</p>
<p>Dessa forma podemos usar uma combinação de Proxy e Reader como HttpProxy e JsonReader:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> store <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    proxy<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">HttpProxy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'projects.json'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    reader<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">JsonReader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        totalProperty<span style="color: #339933;">:</span><span style="color: #3366CC;">'total'</span><span style="color: #339933;">,</span>
        root<span style="color: #339933;">:</span><span style="color: #3366CC;">'results'</span><span style="color: #339933;">,</span>id<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Record</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'created_at'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'created_at'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'updated_at'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'updated_at'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Devido o costume do uso do HttpProxy, o componente Store possui uma propriedade chamada &#8220;url&#8221; que estando presente cria um HttpProxy automaticamente como mostrado abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> store <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'projects.json'</span><span style="color: #339933;">,</span>
    reader<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">JsonReader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        totalProperty<span style="color: #339933;">:</span><span style="color: #3366CC;">'total'</span><span style="color: #339933;">,</span>
        root<span style="color: #339933;">:</span><span style="color: #3366CC;">'results'</span><span style="color: #339933;">,</span>id<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Record</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'created_at'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'created_at'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'updated_at'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'updated_at'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>O objeto &#8220;<strong>Reader</strong>&#8221; é o único que foge um pouco a regra de instanciação por receber dois parâmetros, um similar aos outros com um objeto literal de configuração e outro com o mapeamento dos dados. O objeto de configuração tem duas propriedades de que representam o total e a lista de dados. O objeto de mapeamento usa um método &#8220;estático&#8221; do objeto Record para criar um link entre a propriedade do json [com a propriedade "mapping"] e o índice interno do Record [pela propriedade "name"].</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">JsonReader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        totalProperty<span style="color: #339933;">:</span><span style="color: #3366CC;">'total'</span><span style="color: #339933;">,</span>
        root<span style="color: #339933;">:</span><span style="color: #3366CC;">'results'</span><span style="color: #339933;">,</span>id<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Record</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'created_at'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'created_at'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'updated_at'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'updated_at'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Dessa forma você tem um link entre o ColumnName pela propriedade dataIndex e o Store por meio do Reader, como abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Record</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
         <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'nome_linkado'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #006600; font-style: italic;">//</span>
 columns<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span>header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Nome&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">120</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'nome_linkado'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span></pre></div></div>

<p>Para melhorar a navegação da GRID, você pode também acrescentar um componente de Toolbar no header ou no footer:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> grid  <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">GridPanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    autoShow<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span><span style="color: #CC0000;">750</span><span style="color: #339933;">,</span>height<span style="color: #339933;">:</span><span style="color: #CC0000;">250</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//parametros de configuração de layout</span>
    cm<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">ColumnModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #006600; font-style: italic;">/*configuração*/</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    store<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//Ou especialização de um Store</span>
    sm<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">RowSelectionModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>singleSelect<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    bbar<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">Toolbar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//Bottom Toolbar</span>
    tbar<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">Toolbar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">//Top Toolbar</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>A Toolbar mais usada é sua especialização com paginação, a Ext.PagingToolbar que necessita ser linkada com o Store:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">PagingToolbar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    pageSize<span style="color: #339933;">:</span><span style="color: #CC0000;">10</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//propriedade opcional, default é 20</span>
    store<span style="color: #339933;">:</span> store
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>A PagingToolbar é I18n, mas se as mensagens não agradarem você pode mudá-las [eu sempre faço]:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">PagingToolbar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    pageSize<span style="color: #339933;">:</span><span style="color: #CC0000;">10</span><span style="color: #339933;">,</span>store<span style="color: #339933;">:</span> store<span style="color: #339933;">,</span>
    displayInfo<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>	
    displayMsg<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Exibindo o resultado: {0} a {1} de {2} registros'</span><span style="color: #339933;">,</span>
    emptyMsg<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Sem resultados a exibir&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Uma coisa bacana nesse componente é que você pode agrupar botões [já que é uma Toolbar] e até padronizar o layout:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">PagingToolbar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    pageSize<span style="color: #339933;">:</span><span style="color: #CC0000;">10</span><span style="color: #339933;">,</span>store<span style="color: #339933;">:</span> store<span style="color: #339933;">,</span>
    displayInfo<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>	
    displayMsg<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Exibindo o resultado: {0} a {1} de {2} registros'</span><span style="color: #339933;">,</span>
    emptyMsg<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Sem resultados a exibir&quot;</span><span style="color: #339933;">,</span>
    items<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'-'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        pressed<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>enableToggle<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>text<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Alterar'</span><span style="color: #339933;">,</span>
        toggleHandler<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: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        pressed<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>enableToggle<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>text<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Excluir'</span><span style="color: #339933;">,</span>
        toggleHandler<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: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Código da GRID inteira:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> store <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    proxy<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">HttpProxy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'projects.json'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    reader<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">JsonReader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        totalProperty<span style="color: #339933;">:</span><span style="color: #3366CC;">'total'</span><span style="color: #339933;">,</span>
        root<span style="color: #339933;">:</span><span style="color: #3366CC;">'results'</span><span style="color: #339933;">,</span>id<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Record</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'created_at'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'created_at'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'updated_at'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'updated_at'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> colModel <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">ColumnModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
    <span style="color: #009900;">&#123;</span>id<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span>header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Nome&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">120</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span>header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Criado em&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">135</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> 
        renderer<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000066; font-weight: bold;">return</span> Date.<span style="color: #660066;">parseDate</span><span style="color: #009900;">&#40;</span>value<span style="color: #339933;">,</span> <span style="color: #3366CC;">'Y-m-d<span style="color: #000099; font-weight: bold;">\\</span>TH:i:s<span style="color: #000099; font-weight: bold;">\\</span>Z'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">format</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'d/m/Y H:i:s'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'created_at'</span><span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> pagingToolbar <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">PagingToolbar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    pageSize<span style="color: #339933;">:</span><span style="color: #CC0000;">10</span><span style="color: #339933;">,</span>store<span style="color: #339933;">:</span> store<span style="color: #339933;">,</span>
    displayInfo<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>	
    displayMsg<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Exibindo o resultado: {0} a {1} de {2} registros'</span><span style="color: #339933;">,</span>
    emptyMsg<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Sem resultados a exibir&quot;</span><span style="color: #339933;">,</span>
    items<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'-'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        pressed<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>enableToggle<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>text<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Alterar'</span><span style="color: #339933;">,</span>
        toggleHandler<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: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        pressed<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>enableToggle<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>text<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Excluir'</span><span style="color: #339933;">,</span>
        toggleHandler<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: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> grid  <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">GridPanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    autoShow<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span><span style="color: #CC0000;">750</span><span style="color: #339933;">,</span>height<span style="color: #339933;">:</span><span style="color: #CC0000;">250</span><span style="color: #339933;">,</span>
    cm<span style="color: #339933;">:</span> colModel<span style="color: #339933;">,</span>
    store<span style="color: #339933;">:</span> store<span style="color: #339933;">,</span>
    sm<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">RowSelectionModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>singleSelect<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    bbar<span style="color: #339933;">:</span> pagingToolbar
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Como eu falei, todos os componentes possuem o mesmo comportamento, notaram que dá para aproveitar esse código semelhante e reaproveitar em todos os CRUDs?<br />
Vou falando de um por um de acordo com os posts que forem saindo, aguardem que o próximo sai logo&#8230; ou não.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2009/06/29/introducao-ao-ext/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Encontro em Iguatu</title>
		<link>http://www.milfont.org/tech/2008/11/04/encontro-em-iguatu/</link>
		<comments>http://www.milfont.org/tech/2008/11/04/encontro-em-iguatu/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 12:19:34 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[cejug]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[DWR]]></category>
		<category><![CDATA[Ext]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[palestras]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[web2.0]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>
		<category><![CDATA[YUI]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Jquery]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/?p=365</guid>
		<description><![CDATA[O evento em Iguatu foi excelente, tivemos uma tarde muito agradável no encontro das comunidades PHP e Java no dia 1/11/2008. Fernando Chucre iniciou o evento palestrando pelo CEPUG sobre PHP Orientado a objetos. Logo em seguida foi a vez do Jefferson [organizador do evento] palestrar sobre Debug no PHP. Pelo CEJUG o Silveira Neto [...]]]></description>
			<content:encoded><![CDATA[<p>O evento em Iguatu foi excelente, tivemos uma tarde muito agradável no <a href="http://www.milfont.org/tech/2008/10/24/encontro-java-e-php-em-iguatu-ce/">encontro das comunidades PHP e Java</a> no dia 1/11/2008.</p>
<p><a href="http://horizontesdigitais.com/">Fernando Chucre</a> iniciou o evento palestrando pelo <a href="http://cepug.org/2008/11/evento-em-iguatu-foi-um-sucesso-agora-e-fortaleza/">CEPUG</a> sobre PHP Orientado a objetos. Logo em seguida foi a vez do <a href="http://jefferson.eti.br/">Jefferson</a> [organizador do evento] palestrar sobre Debug no PHP.<br />
Pelo <a href="http://www.cejug.org/display/cejug/Apresentando+o+CEJUG+e+o+poder+do+Java+e+Frameworks+AJAX+em+Iguatu+-+01.11.08">CEJUG</a> o <a href="http://silveiraneto.net/2008/11/03/1%c2%ba-encontro-cejugcepug-em-iguatu/">Silveira Neto</a> apresentou uma palestra sobre a comunidade e o poder do Java, seguido por mim sobre Frameworks Ajax focado em Java com utilização de DWR e ExtJS.</p>
<p>O detalhe mais importante foi constatar a maturidade de duas comunidades tão distintas que compartilharam o mesmo evento sem nenhum problema, egocentrismo ou picuinha. Eu já estou cansando de ir em eventos onde o pessoal só fala de outra tecnologia, como eventos de linguagem onde falam mal de Java o evento inteiro. Cada um apresentou sua palestra sem desmerecer nenhuma tecnologia ou ninguém.</p>
<h2>Material</h2>
<div id="__ss_719498" style="width: 425px; text-align: left;"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" title="Frameworks Ajax" href="http://www.slideshare.net/cmilfont/frameworks-ajax-presentation?type=powerpoint">Frameworks Ajax</a><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=frameworksajax-1225798962914024-9&amp;stripped_title=frameworks-ajax-presentation" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://static.slideshare.net/swf/ssplayer2.swf?doc=frameworksajax-1225798962914024-9&amp;stripped_title=frameworks-ajax-presentation" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="font-size: 11px; font-family: tahoma,arial; height: 26px; padding-top: 2px;">View SlideShare <a style="text-decoration:underline;" title="View Frameworks Ajax on SlideShare" href="http://www.slideshare.net/cmilfont/frameworks-ajax-presentation?type=powerpoint">presentation</a> or <a style="text-decoration:underline;" href="http://www.slideshare.net/upload?type=powerpoint">Upload</a> your own. (tags: <a style="text-decoration:underline;" href="http://slideshare.net/tag/ajax">ajax</a> <a style="text-decoration:underline;" href="http://slideshare.net/tag/iguatu">iguatu</a>)</div>
</div>
<h2>Fotos</h2>
<p><a href="http://picasaweb.google.com.br/cmilfont/Iguatu1112008">Picasa do CMilfont</a><br />
<a href="http://www.flickr.com/photos/silveiraneto/sets/72157608607361149/">Flcikr do Silveira</a></p>
<p><img src="http://lh5.ggpht.com/_Mm7CP-3dJvI/SQ7tkg3kpLI/AAAAAAAAAvc/woXXELjYiJg/s400/IMG_2173.JPG" alt="iguatu" /></p>
<p><img src="http://farm4.static.flickr.com/3163/2997081263_b20482857b.jpg?v=0" alt="minha apresentacao" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2008/11/04/encontro-em-iguatu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ajax Crossbrowser no IE8 e FF3</title>
		<link>http://www.milfont.org/tech/2008/03/09/ajax-crossbrowser-no-ie8-e-ff3/</link>
		<comments>http://www.milfont.org/tech/2008/03/09/ajax-crossbrowser-no-ie8-e-ff3/#comments</comments>
		<pubDate>Mon, 10 Mar 2008 00:50:23 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>
		<category><![CDATA[IE8]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/2008/03/09/ajax-crossbrowser-no-ie8-e-ff3/</guid>
		<description><![CDATA[Uma confusão muito comum até em desenvolvedores profissionais é não saber que o objeto XHR segue o mesmo princípio de segurança do javascript e por isso não pode executar uma chamada remota a outro endereço que não o mesmo de onde o arquivo é chamado. Isso é chamado de &#8220;Same Domain Policy&#8220;. A alternativa para [...]]]></description>
			<content:encoded><![CDATA[<p>Uma confusão muito comum até em desenvolvedores profissionais é <a href="http://www.milfont.org/tech/2008/01/04/jsonrequest-para-evitar-o-eval/#comment-172">não saber</a> que o objeto <a href="http://www.milfont.org/tech/2007/10/03/destilando-o-xmlhttprequest/">XHR</a> segue o mesmo princípio de segurança do javascript e por isso não pode executar uma chamada remota a outro endereço que não o mesmo de onde o arquivo é chamado. Isso é chamado de &#8220;<a href="http://en.wikipedia.org/wiki/Same_origin_policy">Same Domain Policy</a>&#8220;.</p>
<p>A alternativa para contornar esse problema é usar a estratégia de <a href="http://www.milfont.org/tech/2007/10/08/script-tag/">Scripttag</a> quando o recurso externo permite ou usar um script como proxy no servidor para buscar o recurso e devolver via Ajax. Existem outras formas mais porcas de fazer isso que nem merecem consideração.</p>
<p>O Firefox 3 vem com o recurso de <a href="http://developer.mozilla.org/en/docs/Cross-Site_XMLHttpRequest">XHR Crossbrowser</a>, agora seguido do <a href="http://go.microsoft.com/fwlink?LinkID=110280">IE8</a>. Sinceramente isso não muda nada a curto prazo, até termos as versões anteriores do FF e principalmente do IE aposentadas, teremos que contornar isso com as gambiarras de sempre.</p>
<p>O <a href="http://ejohn.org/about/">John Resig</a> (Criador do JQuery) mostra <a href="http://ejohn.org/blog/cross-site-xmlhttprequest/">nesse post</a> como usar isso no FF3. Lembrando que isso só funciona no FF3 que ainda é beta.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2008/03/09/ajax-crossbrowser-no-ie8-e-ff3/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>JSONRequest para evitar o Eval</title>
		<link>http://www.milfont.org/tech/2008/01/04/jsonrequest-para-evitar-o-eval/</link>
		<comments>http://www.milfont.org/tech/2008/01/04/jsonrequest-para-evitar-o-eval/#comments</comments>
		<pubDate>Fri, 04 Jan 2008 12:07:27 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>
		<category><![CDATA[Crockford]]></category>
		<category><![CDATA[Douglas Crockford]]></category>
		<category><![CDATA[JSONRequest]]></category>
		<category><![CDATA[W3C]]></category>
		<category><![CDATA[XHR]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/2008/01/04/jsonrequest-para-evitar-o-eval/</guid>
		<description><![CDATA[Em artigo passado, vimos a proposta de Douglas Crockford, denominado de JSON (JavaScript Object Notation) para a troca de dados. Ele propôs também uma especificação para um novo objeto como serviço nativo nos navegadores, JSONRequest, devido a ineficiência do objeto XMLHttpRequest para as novas aplicações nas próximas geração WEB (WEB 2+). Um dos pontos principais [...]]]></description>
			<content:encoded><![CDATA[<p>Em <a href="http://www.milfont.org/tech/2007/11/04/o-que-e-json/">artigo passado</a>, vimos a proposta de Douglas <a href="http://www.crockford.com/">Crockford</a>, denominado de <a href="http://www.json.org/">JSON</a> (JavaScript Object Notation) para a troca de dados. Ele propôs também uma especificação para um novo objeto como serviço nativo nos navegadores, <a href="http://www.json.org/JSONRequest.html">JSONRequest</a>, devido a ineficiência do objeto <a href="http://www.milfont.org/tech/2007/10/03/destilando-o-xmlhttprequest/">XMLHttpRequest</a> para as novas aplicações nas próximas geração WEB (WEB 2+). Um dos pontos principais desse novo objeto é a troca segura de objetos por meio de JSON entre o lado cliente e servidor sem expô-los ao perigo.</p>
<p>A especificação do <a href="http://www.milfont.org/tech/2007/10/03/destilando-o-xmlhttprequest/">XHR</a> define, por medida de segurança, que uma chamada remota só pode ser efetuada ao mesmo caminho de onde o script foi baixado, o JSONRequest resolveria esse problema habilitando o navegador a uma chamada remota a outros servidores diferentes do host original da página, possibilitando a facilidade de acesso a WEB Services REST na camada javascript.</p>
<p>Hoje como alternativa a esse modelo do <a href="http://www.milfont.org/tech/2007/10/03/destilando-o-xmlhttprequest/">XHR</a> temos o <a href="http://www.milfont.org/tech/2007/10/08/script-tag/">Scripttag</a>, dessa forma conseguimos acessar recursos remotos de outros servidores mas com o problema de XSS (cross site scripting). O problema principal do XSS é a injeção de código malicioso pelo parser a partir do método &#8220;Eval&#8221; para processar o código recebido. Vimos uma <a href="http://www.milfont.org/tech/2007/10/02/eval-is-evil/">alternativa de contornar</a> o problema mas mesmo assim não é suficiente. Uma das vantagens principais do JSONRequest seria evitar o XSS.</p>
<p>Esse objeto JSONRequest seria nativo e global, desenhado para ser simples, teria apenas 3 métodos: get, post e cancel.</p>
<p>Existe já plugin para o <a href="http://crypto.stanford.edu/jsonrequest/">Firefox</a>  que habilita o navegador a oferecer nativamente o objeto JSONRequest.</p>
<p>Para todos os navegadores somente com javascript na camada mais alta, para isso existe também o projeto <a href="http://www.devpro.it/JSON/files/JSON-js.html">JSONRequest</a> de <a href="http://www.3site.eu/">Andrea Giammarchi</a>, que criou o objeto em javascript seguindo a especificação. Compatível com os principais navegadores: Opera, IE, Firefox, Safari e konqueror.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
    JSONRequest.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;processaJSON.jsp&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>sn<span style="color: #339933;">,</span> response<span style="color: #339933;">,</span> exception<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
             <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>exception <span style="color: #339933;">||</span> response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
      <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>O W3C <a href="http://www.w3.org/TR/access-control/">especificou</a> medidas seguras para acesso a recursos web em outro servidores, assim como já existem <a href="http://wiki.mozilla.org/Cross_Site_XMLHttpRequest">movimentos</a> para uma nova especificação do um novo <a href="http://lists.w3.org/Archives/Public/public-webapi/2006Jun/0012">XHR</a>, seria algo como um <a href="http://www.w3.org/2006/webapi/track/products/8">XHR2</a>. A diferença no meu entendimento é que o JSONRequest trata exclusivamente da troca de objetos nativos com base em JSON entre os dois ambientes físicos, enquanto o XHR trata da troca via XML, portanto uma nova especificação do XHR não seria suficiente para substituir a proposta do JSONRequest, a não ser que ele fizesse o parser também de JSON como faz com XML.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2008/01/04/jsonrequest-para-evitar-o-eval/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Material da minha primeira palestra sobre Ajax</title>
		<link>http://www.milfont.org/tech/2007/10/29/material-da-minha-primeira-palestra-sobre-ajax/</link>
		<comments>http://www.milfont.org/tech/2007/10/29/material-da-minha-primeira-palestra-sobre-ajax/#comments</comments>
		<pubDate>Mon, 29 Oct 2007 04:51:18 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[cursos]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[web2.0]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/2007/10/28/material-da-minha-primeira-palestra-sobre-ajax/</guid>
		<description><![CDATA[Essa palestra foi ministrada na SEAD-CE (hoje SEPLAG-CE), a primeira que falei sobre Ajax.]]></description>
			<content:encoded><![CDATA[<p>Essa <a href="http://www.milfont.org/blog/archives/80">palestra</a> foi ministrada na SEAD-CE (hoje <a href="http://www.seplag.ce.gov.br/">SEPLAG-CE</a>), a primeira que falei sobre Ajax.</p>
<iframe src="http://www.slideshare.net/slideshow/embed_code/" width="400" height="337" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe><br/><br/>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2007/10/29/material-da-minha-primeira-palestra-sobre-ajax/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Script Tag</title>
		<link>http://www.milfont.org/tech/2007/10/08/script-tag/</link>
		<comments>http://www.milfont.org/tech/2007/10/08/script-tag/#comments</comments>
		<pubDate>Mon, 08 Oct 2007 16:51:22 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/2007/10/08/script-tag/</guid>
		<description><![CDATA[Para implementar o dinamismo nas nossas páginas, usando o Javascript, precisamos trocar informações entre as camadas físicas diferentes, o cliente (por intermédio de um Browser) solicitando recursos de um servidor remoto (lado servidor). Dentre as estratégias para essa troca de recursos entre as camadas distintas, temos IFrame, XHR e o Scripttag. IFrame era uma técnica [...]]]></description>
			<content:encoded><![CDATA[<p>Para implementar o dinamismo nas nossas páginas, usando o Javascript, precisamos trocar informações entre as camadas físicas diferentes, o cliente (por intermédio de um Browser) solicitando recursos de um servidor remoto (lado servidor).</p>
<p>Dentre as estratégias para essa troca de recursos entre as camadas distintas, temos IFrame, <a href="http://www.milfont.org/tech/category/web-development/xmlhttprequest/">XHR</a> e o Scripttag.</p>
<p>IFrame era uma técnica muito comum na era pré-ajax, mas que causava vários problemas, além da complexidade desnecessária e natureza gambiarrosa. Um dos problemas da técnica era quando se perdia a referência entre os frames e as páginas que os evocam (acontecia com uma frequência não tão insignificante). Geralmente os frameworks implementam a técnica de IFrame por questão de compatibilidade com browsers mais antigos. Quem não se lembra do escondido.jsp (ou escondido.php, escondido.asp, escondido.etc &#8230;)?</p>
<p>Como vimos em um <a href="http://www.milfont.org/tech/2007/10/02/eval-is-evil/">post passado</a>, a técnica de usar o XHR nos proporciona trabalhar com o parsing de XML ou a montagem dinâmica de objetos serializáveis, seja com &#8220;Eval&#8221; ou usando a capacidade dinâmica da linguagem de definir objetos de forma simples em tempo de execução. Vimos que usar Eval não é bom porque &#8220;<a href="http://www.milfont.org/tech/2007/10/02/eval-is-evil/">Eval is Evil</a>&#8220;.</p>
<p>A técnica de Scripttag  está em alta porque aproveita a própria capacidade do browser para instanciar um trecho de código serializável entre as camadas físicas distintas. A técnica está descrita no <a href="http://ajaxpatterns.org/On-Demand_Javascript">Pattern</a> Lazy Loading Javascript ou  On-Demand javascript</p>
<p>A técnica consiste em se obter um recurso do servidor em forma de texto, mas já formatado como um código (entidade) javascript e adicionar esse trecho na seção head da página, fazendo com que o próprio Browser instancie como se estivesse lendo a página na carga inicial. Vejamos:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> JSONRequest<span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> head <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;head&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> script <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   script.<span style="color: #660066;">id</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'TriadworksOnDemand'</span><span style="color: #339933;">;</span>
   script.<span style="color: #660066;">type</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'text/javascript'</span><span style="color: #339933;">;</span>
   script.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> url<span style="color: #339933;">;</span>
   head.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>script<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> montaGrid<span style="color: #009900;">&#40;</span>usuarios<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//aguarda um array de usuarios</span>
    <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #000066; font-weight: bold;">in</span> usuarios<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">//pega usuarios[x]...</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> pesquisar<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://server_path/usuario/'</span><span style="color: #339933;">+</span>id
                 <span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;/?callback=&quot;</span><span style="color: #339933;">+</span>montaGrid<span style="color: #339933;">;</span>
    JSONRequest<span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
pesquisar<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">101</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Observe que criamos uma função chamada JSONRequest, que basicamente pega uma url e adiciona dinamicamente na seção head da página. Essa url é uma saída texto pelo servidor no formato JSON, utilizando o modelo REST para obter um recurso, ou seja, o servidor responde com um objeto serializável no endereço /usuario/id porque ele reconhece que as requisições a esse endereço são lógicas CRUD para a captura do recurso &#8220;usuário&#8221;. Passo como parâmetro uma variável chamada callback para o servidor renderizar a execução dessa função para ser interpretada assim que o Browser anexar a resposta.</p>
<p>A resposta viria mais ou menos assim:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">montaGrid<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span>
          <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'101'</span><span style="color: #339933;">,</span>
           <span style="color: #3366CC;">'nome'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'Christiano'</span><span style="color: #339933;">,</span>
           <span style="color: #3366CC;">'sobrenome'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'Milfont'</span><span style="color: #339933;">,</span>
           <span style="color: #3366CC;">'email'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'cmilfont@gmail.com'</span>
          <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span></pre></div></div>

<p>AO executar a função <strong>JSONRequest</strong>, o código anexa a resposta do servidor na seção Head da página e então o Browser interpreta como se estivesse lendo na carga da página, executando a função montaGrid.</p>
<p>Diferenças entre as abordagens Scripttag e XHR.</p>
<table>
<tr>
<th scope="col"></th>
<th scope="col">XmlHttpRequest</th>
<th scope="col">Dynamic script Tag</th>
</tr>
<tr>
<th scope="row">Compatível com Cross-browser?</th>
<td>Não *</td>
<td>Sim</td>
</tr>
<tr>
<th scope="row">Cross-domain browser security enforced?</th>
<td>Sim</td>
<td>Não</td>
</tr>
<tr>
<th scope="row">Trabalha com  HTTP status codes?</th>
<td>Sim</td>
<td>Não (falha com outro código HTTP diferente de  200)</td>
</tr>
<tr>
<th scope="row">Supports HTTP GET and POST?</th>
<td>Sim</td>
<td>Não (Somente GET)</td>
</tr>
<tr>
<th scope="row">Pode receber/enviar HTTP headers?</th>
<td>Sim</td>
<td>Não</td>
</tr>
<tr>
<th scope="row">Pode receber XML?</th>
<td>Sim</td>
<td>Sim (mas embutido na sentença JavaScript)</td>
</tr>
<tr>
<th scope="row">Pode receber JSON?</th>
<td>Sim</td>
<td>Sim (mas embutido na sentença JavaScript)</td>
</tr>
<tr>
<th scope="row">Oferece chamadas síncronas e assíncronas?</th>
<td>Sim</td>
<td>Não (somente assíncronas)</td>
</tr>
</table>
<p>* &#8211; Basicamente poderíamos dizer que é compatível sim, mas com a diferença na implementação. Somente os browsers mais antigos não possuirão o objeto necessário.</p>
<p>Então o uso racional das abordagens vai depender da necessidade de características de cada uma, cada qual possui suas vantagens e desvantagens. Mais em <a href="http://www.xml.com/lpt/a/1636">XML.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2007/10/08/script-tag/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Destilando o XMLHttpRequest</title>
		<link>http://www.milfont.org/tech/2007/10/03/destilando-o-xmlhttprequest/</link>
		<comments>http://www.milfont.org/tech/2007/10/03/destilando-o-xmlhttprequest/#comments</comments>
		<pubDate>Wed, 03 Oct 2007 18:32:59 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/2007/10/03/destilando-o-xmlhttprequest/</guid>
		<description><![CDATA[O modelo que passou a ser conhecido como Ajax, termo criado por Jesse James Garrett, ficou famoso ap&#243;s o lan&#231;amento do GMail, a capacidade de obter recursos remotos sem precisar dar um refresh na p&#225;gina, modificou toda a forma de pensar no desenvolvimento web. A interface de usu&#225;rio sa&#237;a de uma estrutura puramente est&#225;tica e [...]]]></description>
			<content:encoded><![CDATA[<p>O modelo que passou a ser conhecido como <a href="http://en.wikipedia.org/wiki/AJAX">Ajax</a>, termo criado por <a href="http://blog.jjg.net/">Jesse James Garrett</a>,  ficou famoso ap&oacute;s o lan&ccedil;amento do GMail, a capacidade de obter recursos  remotos sem precisar dar um refresh na p&aacute;gina, modificou toda a forma  de pensar no desenvolvimento web. A interface de usu&aacute;rio sa&iacute;a de uma  estrutura puramente est&aacute;tica e passou a ser semelhante ao ambiente  desktop.</p>
<p>Sua implementa&ccedil;&atilde;o &eacute; poss&iacute;vel por causa do objeto javascript<a href="http://www.w3.org/TR/XMLHttpRequest/"> XMLHttpRequest</a> que faz uma conex&atilde;o ass&iacute;ncrona ao servidor e permite que o usu&aacute;rio  continue seu trabalho sem bloquear a p&aacute;gina. Na &eacute;poca n&atilde;o era  especificado ainda pelo W3C.</p>
<p>O XMLHttpRequest surgiu como uma <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/63409298-0516-437d-b5af-68368157eae3.asp">implementa&ccedil;&atilde;o propriet&aacute;ria da Microsoft</a> e posteriormente criado no <a href="http://developer.mozilla.org/en/docs/XMLHttpRequest">Mozilla em 2002</a>, logo seguido pelos demais Browsers. A <a href="http://www.w3.org/TR/XMLHttpRequest/#xmlhttprequest">interface</a> definida pelo W3C ser&aacute; o objeto de estudo desse artigo.</p>
<p>Uma conex&atilde;o remota de forma ass&iacute;ncrona segue o seguinte esquema:</p>
<p><img src="http://www.milfont.org/tech/wp-content/uploads/2007/10/request_ajax.gif" alt="request_ajax.gif" /></p>
<ol>
<li>Um evento &eacute; disparado para dar in&iacute;cio a execu&ccedil;&atilde;o;</li>
<li>Um objeto XMLHttpRequest &eacute; criado e configurado;</li>
<li>Uma requisi&ccedil;&atilde;o de um recurso &eacute; feita para o servidor;</li>
<li>O servidor realizada sua l&oacute;gica de neg&oacute;cio e devolve o recurso na forma de texto comum (que deve ser um xml em formado);</li>
<li>Uma fun&ccedil;&atilde;o de callback, previamente informada, manipula os dados retornados;</li>
<li>A renderiza&ccedil;&atilde;o ao usu&aacute;rio &eacute; realizada.</li>
</ol>
<p>A cria&ccedil;&atilde;o e configura&ccedil;&atilde;o do objeto, como o envio de requisi&ccedil;&atilde;o pelo  XMLHttpRequest para a captura de um recurso remoto segue os seguintes  passos:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//instancia um novo objeto</span>
<span style="color: #003366; font-weight: bold;">var</span> ajax <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;">//Configura uma function para a manipulação</span>
<span style="color: #006600; font-style: italic;">//da reposta</span>
ajax.<span style="color: #660066;">onreadystatechange</span> <span style="color: #339933;">=</span> handler<span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//abre a conexão</span>
ajax.<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> <span style="color: #3366CC;">&quot;test.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//envia a requisição</span>
ajax.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Caso a conex&atilde;o seja pelo m&eacute;todo &quot;POST&quot;, o m&eacute;todo send recebe como par&acirc;metro, as vari&aacute;veis a serem enviadas.</p>
<h3>Cria&ccedil;&atilde;o do objeto</h3>
<p>A Microsoft s&oacute; implementou a interface XMLHttpRequest como um objeto  nativo a partir do Internet Explorer 7, antes disso o objeto era um  ActiveX. Apesar que os m&eacute;todos e propriedades haviam sido copiados  desse ActiveX, garantindo o funcionamento id&ecirc;ntico a todos os Browsers  que suportam o XMLHttpRequest.</p>
<p>Ent&atilde;o para as vers&otilde;es anteriores do IE, h&aacute; a necessidade de cria&ccedil;&atilde;o customizada, eis:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">    <span style="color: #003366; font-weight: bold;">var</span> http<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
	    <span style="color: #006600; font-style: italic;">//cria o objeto caso o Browser</span>
        <span style="color: #006600; font-style: italic;">//seja compatível com o W3C</span>
        http <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: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">//caso IE &lt; IE7</span>
        <span style="color: #006600; font-style: italic;">//array com versões conhecidas</span>
        <span style="color: #006600; font-style: italic;">//de implementações do ActiveX</span>
        <span style="color: #003366; font-weight: bold;">var</span> msxml <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
                   <span style="color: #3366CC;">'MSXML2.XMLHTTP.3.0'</span><span style="color: #339933;">,</span> 
                   <span style="color: #3366CC;">'MSXML2.XMLHTTP'</span><span style="color: #339933;">,</span> 
                   <span style="color: #3366CC;">'Microsoft.XMLHTTP'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> len <span style="color: #339933;">=</span> msxml.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #006600; font-style: italic;">//varre o array até identificar qual ActiveX</span>
                http <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span>msxml<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Conhecendo a Interface</h3>
<p>Representa&ccedil;&atilde;o da Interface</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">interface XMLHttpRequest <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// event handler</span>
  attribute EventListener onreadystatechange<span style="color: #339933;">;</span>
  <span style="color: #006600; font-style: italic;">// state</span>
  <span style="color: #003366; font-weight: bold;">const</span> unsigned short UNSENT <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">const</span> unsigned short <span style="color: #000066;">OPEN</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">const</span> unsigned short SENT <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">const</span> unsigned short LOADING <span style="color: #339933;">=</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">const</span> unsigned short DONE <span style="color: #339933;">=</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">;</span>
  readonly attribute unsigned short readyState<span style="color: #339933;">;</span>
  <span style="color: #006600; font-style: italic;">// request</span>
  <span style="color: #000066; font-weight: bold;">void</span> <span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">in</span> DOMString method<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">in</span> DOMString url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">void</span> <span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">in</span> DOMString method<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">in</span> DOMString url<span style="color: #339933;">,</span> 
            <span style="color: #000066; font-weight: bold;">in</span> boolean async<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">void</span> <span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">in</span> DOMString method<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">in</span> DOMString url<span style="color: #339933;">,</span> 
            <span style="color: #000066; font-weight: bold;">in</span> boolean async<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">in</span> DOMString user<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">void</span> <span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">in</span> DOMString method<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">in</span> DOMString url<span style="color: #339933;">,</span> 
            <span style="color: #000066; font-weight: bold;">in</span> boolean async<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">in</span> DOMString user<span style="color: #339933;">,</span> 
            <span style="color: #000066; font-weight: bold;">in</span> DOMString password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">void</span> setRequestHeader<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">in</span> DOMString header<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">in</span> DOMString value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">void</span> send<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">void</span> send<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">in</span> DOMString data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">void</span> send<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">in</span> Document data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">void</span> abort<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #006600; font-style: italic;">// response</span>
  DOMString getAllResponseHeaders<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  DOMString getResponseHeader<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">in</span> DOMString header<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  readonly attribute DOMString responseText<span style="color: #339933;">;</span>
  readonly attribute Document responseXML<span style="color: #339933;">;</span>
  readonly attribute unsigned short <span style="color: #000066;">status</span><span style="color: #339933;">;</span>
  readonly attribute DOMString statusText<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<h4>Event Listener</h4>
<p>A Interface XMLHttpRequest possui um EventListener denominado &quot;<strong>onreadystatechange</strong>&quot;, que &eacute; um manipulador de eventos que &eacute; invocado quando o evento readystatechange &eacute; acionado. Passamos uma fun&ccedil;&atilde;o de tratamento a esse EventListener que verificar&aacute; os estados da conex&atilde;o. </p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//obtem uma instancia</span>
<span style="color: #003366; font-weight: bold;">var</span> ajax <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;">//seta o EventListener com o handler</span>
ajax.<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: #006600; font-style: italic;">//testa se já recebeu e foi com sucesso</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">readyState</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">4</span>  <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">this</span>.<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>
        <span style="color: #006600; font-style: italic;">//obtem o xml enviado pelo servidor</span>
        <span style="color: #003366; font-weight: bold;">var</span> xml <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">responseXML</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<h4>Propriedades</h4>
<p>A Interface possui uma propriedade denominada &quot;<strong>readyState</strong>&quot; que recebe o valor de uma constante que representa o estado atual da conex&atilde;o. As constantes que representam os estados s&atilde;o definidos como:</p>
<ol>
<li>UNSENT = 0; //Apenas instanciado </li>
<li>OPEN = 1; //aberta </li>
<li>SENT = 2; //enviada </li>
<li>LOADING = 3; //abrindo </li>
<li>DONE = 4; //realizada </li>
</ol>
<p>A propriedade &quot;<strong>status</strong>&quot; da Interface, representa o c&oacute;digo de status do protocolo HTTP enviado pelo servidor, como o c&oacute;digo &quot;200&quot; para uma requisi&ccedil;&atilde;o com sucesso. Caso o recurso n&atilde;o esteja dispon&iacute;vel, &eacute; lan&ccedil;ado uma exce&ccedil;&atilde;o INVALID_STATE_ERR pelo Browser. A lista de &quot;<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">HTTP Status Code</a>&quot; voc&ecirc; encontra <a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes">aqui</a>. </p>
<p>A propriedade  &quot;<strong>statusText</strong>&quot;, &eacute; a mensagem texto do &quot;HTTP status code&quot;, e &eacute; recebida logo ap&oacute;s ele, como &quot;Not Found&quot; para o &quot;status code&quot; 404, que indica que o recurso n&atilde;o foi encontrado no servidor de destino. </p>
<p>As propriedades &quot;<strong>responseText</strong>&quot; e &quot;<strong>responseXML</strong>&quot;, devolvem a resposta do servidor na forma de uma DOMString (texto) e Document (da especifica&ccedil;&atilde;o DOM) respectivamente, em outras palavras, devolve um texto puro no caso do responseText ou um xml parseado no caso do responseXML. </p>
<h4>M&eacute;todos</h4>
<p>O m&eacute;todo &quot;<strong>abort</strong>&quot; cancela a requisi&ccedil;&atilde;o, entretanto ele percorre uma s&eacute;rie de atividades dependendo do estado da requisi&ccedil;&atilde;o no momento que &eacute; invocado. Para uma explana&ccedil;&atilde;o mais apropriada no mecanismo que o abort realizada, visite esse <a href="http://www.w3.org/TR/XMLHttpRequest/#dfn-abort">link da especifica&ccedil;&atilde;o da Interface</a>. </p>
<p>O m&eacute;todo &quot;<strong>open</strong>&quot; &eacute; overloaded na Interface, apesar de <a href="http://www.milfont.org/tech/2007/10/01/overloading-e-overriding-no-javascript/">n&atilde;o existir overloading em javascript</a>. Leve em considera&ccedil;&atilde;o que &eacute; um s&oacute;, na implementa&ccedil;&atilde;o o n&uacute;mero de argumentos passados tem a ver com a funcionalidade dependente do m&eacute;todo, exemplo, os par&acirc;metros &quot;user&quot; e &quot;password&quot; s&atilde;o necess&aacute;rios apenas no caso de url restrita no servidor, e caso o par&acirc;metro &quot;async&quot; n&atilde;o seja definido, a conex&atilde;o &eacute; ass&iacute;ncrona por default. Os primeiro par&acirc;metro representa o m&eacute;todo <a href="http://ietf.org/rfc/rfc2616">HTTP de requisi&ccedil;&atilde;o</a>, que pode ser dos tipos: POST, GET, PUT, HEAD, DELETE e OPTIONS. O segundo par&acirc;metro &eacute; a url que receber&aacute; a requisi&ccedil;&atilde;o, o terceiro, quarto e quinto s&atilde;o opcionais como j&aacute; falado.</p>
<p>O m&eacute;todo &quot;<strong>setRequestHeader</strong>&quot;  &eacute; usado antes do m&eacute;todo &quot;<strong>send</strong>&quot; e habilita enviar informa&ccedil;&otilde;es de cabe&ccedil;alho na requisi&ccedil;&atilde;o quando for disparado os recursos ao servidor.</p>
<p>O m&eacute;todo &quot;<strong>send</strong>&quot;  envia a requisi&ccedil;&atilde;o com o argumento opcional &quot;data&quot; que &eacute; do tipo &quot;Text&quot; ou &quot;Document&quot;.</p>
<p>Quando o m&eacute;todo de requisi&ccedil;&atilde;o escolhido &eacute; o GET, os argumentos a serem enviados ao servidor &eacute; usado no par&acirc;metro &quot;url&quot;, como &quot;/pagina.jsp?id=1&amp;nome=milfont&quot;. J&aacute; no m&eacute;todo POST, os dados ser&atilde;o enviados como argumento do m&eacute;todo &quot;send&quot; </p>
<h4>C&oacute;digo completo de uma submiss&atilde;o Ajax</h4>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">    <span style="color: #003366; font-weight: bold;">var</span> http<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
        http <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: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> msxml <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
                   <span style="color: #3366CC;">'MSXML2.XMLHTTP.3.0'</span><span style="color: #339933;">,</span> 
                   <span style="color: #3366CC;">'MSXML2.XMLHTTP'</span><span style="color: #339933;">,</span> 
                   <span style="color: #3366CC;">'Microsoft.XMLHTTP'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> len <span style="color: #339933;">=</span> msxml.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
                http <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span>msxml<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    http.<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><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">readyState</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">4</span>  <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">this</span>.<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>
           <span style="color: #003366; font-weight: bold;">var</span> xml <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">responseXML</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> params <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;id=1&amp;name=milfont&quot;</span><span style="color: #339933;">;</span>
    http.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;pagina.jsp&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    http.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Content-type&quot;</span><span style="color: #339933;">,</span> 
	                  <span style="color: #3366CC;">&quot;application/x-www-form-urlencoded&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    http.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Content-length&quot;</span><span style="color: #339933;">,</span> params.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    http.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Connection&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;close&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    http.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span>params<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Para mais features nas pr&oacute;ximas vers&otilde;es da especifica&ccedil;&atilde;o mas que j&aacute; podem existir nas implementa&ccedil;&otilde;es, <a href="http://www.w3.org/TR/XMLHttpRequest/#notcovered">visite esse link</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2007/10/03/destilando-o-xmlhttprequest/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

