diff options
Diffstat (limited to 'files/es/web/api/response/ok')
-rw-r--r-- | files/es/web/api/response/ok/index.html | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/files/es/web/api/response/ok/index.html b/files/es/web/api/response/ok/index.html new file mode 100644 index 0000000000..1bff7fe5db --- /dev/null +++ b/files/es/web/api/response/ok/index.html @@ -0,0 +1,66 @@ +--- +title: Response.ok +slug: Web/API/Response/ok +translation_of: Web/API/Response/ok +--- +<div>{{APIRef("Fetch")}}<br> +La propiedad de solo lectura <code><strong>ok</strong></code> de la interfaz {{domxref("Response")}} contiene un Booleano que indica si la respuesta fue exitosa (estado en un rango de 200 a 299) o no.</div> + +<h2 id="Sintaxis">Sintaxis</h2> + +<pre class="syntaxbox">var <var>miOK</var> = <var>respuesta</var>.ok;</pre> + +<h3 id="Valor">Valor</h3> + +<p>Un {{domxref("Boolean")}}.</p> + +<h2 id="Ejemplo">Ejemplo</h2> + +<p>En nuestro <a href="https://github.com/mdn/fetch-examples/tree/master/fetch-response">ejemplo de Fetch Response</a> (véase <a href="http://mdn.github.io/fetch-examples/fetch-response/">Fetch Response en vivo</a>) creamos un nuevo {{domxref("Request")}} usando el constructor {{domxref("Request.Request","Request()")}}, pasando una ruta a un JPG. Luego traemos esta petición usando {{domxref("GlobalFetch.fetch","fetch()")}}, extraemos un blob de la respuesta usando {{domxref("Body.blob")}}, creamos un objeto URL usando {{domxref("URL.createObjectURL")}}, y mostrar esto en un {{htmlelement("img")}}.</p> + +<div class="note"> +<p><strong>Nota:</strong> en la parte superior del bloque de <code>fetch()</code> imprimimos el valor de <code>ok</code> en la consola.</p> +</div> + +<pre class="brush: js">var imagen = document.querySelector('img'); + +var peticion = new Request('flowers.jpg'); + +fetch(peticion).then(function(respuesta) { + console.log(respuesta.ok); //retorna true si la respuesta fue exitosa + respuesta.blob().then(function(miBlob) { + var objectoURL = URL.createObjectURL(miBlob); + imagen.src = objectURL; + }); +});</pre> + +<h2 id="Especificaciones">Especificaciones</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificación</th> + <th scope="col">Estado</th> + <th scope="col">Comentario</th> + </tr> + <tr> + <td>{{Spec2('Fetch')}}</td> + <td>{{Spec2('Fetch')}}</td> + <td>Definición inicial</td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilidad_de_navegadores">Compatibilidad de navegadores</h2> + + + +<p>{{Compat("api.Response.ok")}}</p> + +<h2 id="Ver_también">Ver también</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/ServiceWorker_API">ServiceWorker API</a></li> + <li><a href="/en-US/docs/Web/HTTP/Access_control_CORS">HTTP access control (CORS)</a></li> + <li><a href="/en-US/docs/Web/HTTP">HTTP</a></li> +</ul> |