aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/api/xmlhttprequest/onreadystatechange/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/pt-br/web/api/xmlhttprequest/onreadystatechange/index.html')
-rw-r--r--files/pt-br/web/api/xmlhttprequest/onreadystatechange/index.html120
1 files changed, 120 insertions, 0 deletions
diff --git a/files/pt-br/web/api/xmlhttprequest/onreadystatechange/index.html b/files/pt-br/web/api/xmlhttprequest/onreadystatechange/index.html
new file mode 100644
index 0000000000..b67e816ae4
--- /dev/null
+++ b/files/pt-br/web/api/xmlhttprequest/onreadystatechange/index.html
@@ -0,0 +1,120 @@
+---
+title: XMLHttpRequest.onreadystatechange
+slug: Web/API/XMLHttpRequest/onreadystatechange
+tags:
+ - AJAX
+ - API
+ - Evento
+ - Manipulador de eventos
+ - XHR
+ - XMLHttpRequest
+translation_of: Web/API/XMLHttpRequest/onreadystatechange
+---
+<div>{{APIRef}}</div>
+
+<p>Um <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventHandler" title="A possible way to get notified of Events of a particular type (such as click) for a given object is to specify an event handler using:"><code>EventHandler</code></a> é chamado sempre que o atributo <code>readyState</code> é modificado. O callback é chamado a partir da interface do usuário. A propriedade <strong><code>XMLHttpRequest.onreadystatechange</code></strong> contém o manipulador de eventos que é chamado quando o evento <a href="/pt-BR/docs/Web/Events/readystatechange">readystatechange</a> é disparado, ou seja, toda vez que a propriedade {{domxref("XMLHttpRequest.readyState", "readyState")}} do {{domxref("XMLHttpRequest")}} é modificada.</p>
+
+<div class="warning">
+<p><strong>Atenção:</strong> Isso não deve ser usado com solicitações síncronas e não deve ser usado como código nativo.</p>
+</div>
+
+<p>O evento <code>readystatechange</code> não será chamado quando a <code>XMLHttpRequest</code> request for cancelada pelo método <a href="/pt-BR/docs/Web/API/XMLHttpRequest/abort">abort()</a>.</p>
+
+<div class="note">
+<p><strong>Atualização</strong>: Está disparando na última versão de navegadores (Firefox 51.0.1, Opera 43.0.2442.991, Safari 10.0.3 (12602.4.8), Chrome 54.0.2840.71, Edge, IE11). Exemplo <a href="https://jsfiddle.net/merksam/ve5oc0gn/">aqui</a> - <em>basta recarregar a página algumas vezes</em>.</p>
+</div>
+
+<h2 id="Syntax" name="Syntax">Sitaxe</h2>
+
+<pre class="syntaxbox"><em>XMLHttpRequest</em>.onreadystatechange = <em>callback</em>;</pre>
+
+<h3 id="Valores">Valores</h3>
+
+<ul>
+ <li><code><em>callback</em></code> é a função que será executada quando o readyState mudar.</li>
+</ul>
+
+<h2 id="Example" name="Example">Exemplo</h2>
+
+<pre class="brush: js">var xhr = new XMLHttpRequest(),
+ method = "GET",
+ url = "https://developer.mozilla.org/";
+
+xhr.open(<em>method</em>, <em>url</em>, true);
+xhr.onreadystatechange = function () {
+ if(xhr.readyState === XMLHttpRequest.DONE &amp;&amp; xhr.status === 200) {
+  console.log(xhr.responseText);
+  }
+ };
+xhr.send();</pre>
+
+<h2 id="Especificação">Especificação</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Especificação</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comentário</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('XMLHttpRequest', '#handler-xhr-onreadystatechange')}}</td>
+ <td>{{Spec2('XMLHttpRequest')}}</td>
+ <td>WHATWG living standard</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilidade_entre_navegadores">Compatibilidade entre navegadores</h2>
+
+<p>{{CompatibilityTable}}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatChrome(1)}}</td>
+ <td>{{CompatGeckoDesktop(1.0)}}</td>
+ <td>{{CompatIe(7)}}<sup>[1]</sup></td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatSafari(1.2)}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Chrome for Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatUnknown}}</td>
+ <td>1.0</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] Internet Explorer versão 5 e 6 suportam chamadas ajax usando <code>ActiveXObject()</code>.</p>