aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/api/response/status/index.html
blob: 86cefd4614dd4da50b34146200cd98795b7d7890 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
title: Response.status
slug: Web/API/Response/status
tags:
  - API
  - Experimental
  - Fetch
  - Property
  - Reference
  - Response
  - status
translation_of: Web/API/Response/status
---
<div>{{APIRef("Fetch")}}</div>

<p>La propiedad de solo lectura <strong><code>status</code></strong> de la interfaz {{domxref("Response")}} contiene el código de estado de la respuesta (ejm., <code>200</code> para un éxito).</p>

<h2 id="Sintaxis">Sintaxis</h2>

<pre class="syntaxbox">var <var>myStatus</var> = <var>response</var>.status;</pre>

<h3 id="Valor">Valor</h3>

<p>Un número (para ser preciso, uno corto sin signo).</p>

<h2 id="Ejemplo">Ejemplo</h2>

<p>En nuestro <a href="https://github.com/mdn/fetch-examples/tree/master/fetch-response">ejemplo Fetch Response</a> (ver <a href="http://mdn.github.io/fetch-examples/fetch-response/">Fetch Response en vivo</a>) nosotros creamos un nuevo objeto {{domxref("Request")}} usando el constructor {{domxref("Request.Request","Request()")}}, pasándole una ruta JPG. Luego buscamos esta solicitud usando  {{domxref("GlobalFetch.fetch","fetch()")}}, extraemos un blob de la respuesta usando {{domxref("Body.blob")}}, creamos un objeto URL fuera de ella usando {{domxref("URL.createObjectURL")}}, y mostramos esto en un {{htmlelement("img")}}.</p>

<p>Tenga en cuenta que en la parte superior del bloque  <code>fetch()</code> registramos el valor de la respuesta  <code>status</code> en la consola.</p>

<pre class="brush: js">var myImage = document.querySelector('img');

var myRequest = new Request('flowers.jpg');

fetch(myRequest).then(function(response) {
  console.log(response.status); // returns 200
  response.blob().then(function(myBlob) {
    var objectURL = URL.createObjectURL(myBlob);
    myImage.src = objectURL;
  });
});</pre>

<h2 id="Especificaciones">Especificaciones</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Especificación</th>
   <th scope="col">Estatus</th>
   <th scope="col">Comentario</th>
  </tr>
  <tr>
   <td>{{SpecName('Fetch','#dom-response-status','status')}}</td>
   <td>{{Spec2('Fetch')}}</td>
   <td>Definición inicial</td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibilidad_del_navegador">Compatibilidad del navegador</h2>



<p>{{Compat("api.Response.status")}}</p>

<h2 id="Ver_también">Ver también</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/ServiceWorker_API">API de Servicio Worker</a></li>
 <li><a href="/en-US/docs/Web/HTTP/Access_control_CORS">Control de acceso HTTP (CORS)</a></li>
 <li><a href="/en-US/docs/Web/HTTP">HTTP</a></li>
</ul>