Skip to content
This repository was archived by the owner on Jan 21, 2023. It is now read-only.

Latest commit

 

History

History
129 lines (105 loc) · 3.07 KB

README.md

File metadata and controls

129 lines (105 loc) · 3.07 KB

/Blog

Demo

Para utilizar otra id, solo necesitas pasarlo como parámetro en la url.

demoid.html?id=870

Ejemplos

/blogs - Peticiones Ajax y respuestas esperadas

Petición Ajax a http://api.rtve.es/api/blogs.json

var xmlHttp = new XMLHttpRequest()

xmlHttp.onreadystatechange = function() {
    var datos = {};
    if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
        datos = JSON.parse(xmlHttp.responseText);
        console.info(datos);
    } else if (xmlHttp.readyState === 4 && xmlHttp.status === 400) {
        datos = JSON.parse(xmlHttp.responseText);
        console.error("ERROR! 400 - Solicitud incorrecta!");         
    } else if (xmlHttp.readyState === 4 && xmlHttp.status === 404) {
        datos = JSON.parse(xmlHttp.responseText);
        console.error("ERROR! 404 - No encontrado!");
    }
};

xmlHttp.open("GET", "http://api.rtve.es/api/blogs.json", true);
xmlHttp.send();

Respuesta esperada

  • page (Object)
    • items (Array)
      • 0 (Object)
      • ...
    • number: Number
    • size: Number
    • offset: Number
    • total: Number
    • totalPages: Number
    • numElements: Number

/blogs/{id} - Peticiones Ajax y respuestas esperadas

Petición Ajax a http://api.rtve.es/api/blogs/3531.json

var xmlHttp = new XMLHttpRequest()

xmlHttp.onreadystatechange = function() {
    var datos = {};
    if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
        datos = JSON.parse(xmlHttp.responseText);
        console.info(datos);
    } else if (xmlHttp.readyState === 4 && xmlHttp.status === 400) {
        datos = JSON.parse(xmlHttp.responseText);
        console.error("ERROR! 400 - Solicitud incorrecta!");         
    } else if (xmlHttp.readyState === 4 && xmlHttp.status === 404) {
        datos = JSON.parse(xmlHttp.responseText);
        console.error("ERROR! 404 - No encontrado!");
    }
};

xmlHttp.open("GET", "http://api.rtve.es/api/blogs/3531.json", true);
xmlHttp.send();

Respuesta esperada

  • page (Object)
    • items (Array)
      • 0 (Object)
        • uri: String
        • htmlUrl: null
        • htmlShortUrl: null
        • id: String
        • language: String
        • longTitle: String
        • shortTitle: String
        • mainCategoryRef: String
        • popularity: null
        • popHistoric: null
        • numVisits: null
        • publicationDate: String
        • expirationDate: null
        • modificationDate: String
        • pubState (Object)
          • code: String
          • description: String
        • breadCrumbRef: String
        • imageSEO: null
        • publicationDateTimestamp: Number
        • contentType: String
        • statistics: null
        • data (Object)
          • url: String
          • rssUrl: String
          • title: String
          • image: String
          • typepadId: String
        • lastPostData (Object)
          • date: String
          • title: String
          • url: String
          • author: String
        • title: String
    • number: Number
    • size: Number
    • offset: Number
    • total: Number
    • totalPages: Number
    • numElements: Number