当网站成功发出相同请求时,Ajax请求失败

时间:2017-06-02 13:47:21

标签: javascript jquery ajax

当用户向下滚动时,

This website会动态加载内容。向下滚动时,网站会发送一个AJAX请求(可以在开发工具>网络选项卡中看到),它返回JSON数据。

当我通过browsing to或我自己的请求手动发出请求时:

value

它返回运行时错误。

$.ajax({
        method: "POST",
        url: "https://resultados4.museodelprado.es/CargadorResultados/CargarResultados",
        success: function(response) {
            data_holder = response;
        }
    });

如何发送AJAX请求以返回JSON数据,而不是运行时错误?

修改

This image shows the devtools > network

1 个答案:

答案 0 :(得分:1)

您的请求不起作用,因为ajax调用需要参数,代码如下所示:

$.ajax({
    method: "POST",
    url: "https://resultados4.museodelprado.es/CargadorResultados/CargarResultados",
    data: {
        cont: 0,
        pAdministradorVeTodasPersonas: false,
        pEsUsuarioInvitado: true,
        pFiltroContexto: "",
        pGrafo: "7317a29a-d846-4c54-9034-6a114c3658fe",
        pIdentidadID: "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF",
        pLanguageCode: "en",
        pNumeroParteResultados: 1,
        pParametros: "|pagina=2",
        pParametros_adiccionales: "PestanyaActualID=c89fbb0c-a52c-4700-9220-79f4964d3949|rdf:type=pmartwork|orden=asc|ordenarPor=pm:relevance,ecidoc:p62_E52_p79_has_time-span_beginning,ecidoc:p62_E52_p80_has_time-span_end,gnoss:hasfechapublicacion",
        pPrimeraCarga: false,
        pProyectoID: "7317a29a-d846-4c54-9034-6a114c3658fe",
        pTipoBusqueda: 0,
        pUsarMasterParaLectura: false
    },
    success: function (response) {
        console.log(response);
    }
});

结果是一个包含2个参数的JSON:KeyValue,如

<div id="numResultadosRemover"> <strong>3421</strong> results </div>
<div class="mostrable miniaturas">
  <figure>
    <div class="imgwrap">
      <a href="https://www.museodelprado.es/en/the-collection/art-work/the-creation-of-adam-the-hermitage-of-the-vera/52e8a064-dfad-43db-a9f9-939eeba21869"> <img src="https://content3.cdnprado.net/imagenes/Documentos/imgsem/52/52e8/52e8a064-dfad-43db-a9f9-939eeba21869/b1ee2320-41b9-4992-bdb2-88ad76fcb5c6_268.jpg" alt=""> </a> <a href="https://www.museodelprado.es/en/cmspagina?ComponentName=operativaLogin&amp;titulo=The+Creation+of+Adam.+The+Hermitage+of+the+Vera+Cruz+de+Maderuelo&amp;imagen=https%3a%2f%2fcontent3.cdnprado.net%2fimagenes%2fDocumentos%2fimgsem%2f52%2f52e8%2f52e8a064-dfad-43db-a9f9-939eeba21869%2fb1ee2320-41b9-4992-bdb2-88ad76fcb5c6_268.jpg&amp;idobra=52e8a064-dfad-43db-a9f9-939eeba21869" class="mi-prado modal-popup" href="#">Add to My Prado</a> </div>
    <figcaption class="presentacion-mosaico">
      <dl> <dt class="trunca-texto"><a href="https://www.museodelprado.es/en/the-collection/art-work/the-creation-of-adam-the-hermitage-of-the-vera/52e8a064-dfad-43db-a9f9-939eeba21869">The Creation of Adam. The Hermitage of the Vera Cruz de Maderuelo</a></dt>
        <dd class="trunca-texto soporte">Fresco painting on mural transferred to canvas. XII century</dd>
        <dd class="trunca-texto autor"><a href="https://www.museodelprado.es/en/the-collection/art-works?cidoc:p14_carried_out_by@@@pm:author@@@ecidoc:p131_E82_p102_has_title=anonymous@en">Anonymous</a>
        </dd>
      </dl>
    </figcaption>
    <figcaption class="presentacion-listado">
      <dl> <dt><a href="https://www.museodelprado.es/en/the-collection/art-work/the-creation-of-adam-the-hermitage-of-the-vera/52e8a064-dfad-43db-a9f9-939eeba21869">The Creation of Adam. The Hermitage of the Vera Cruz de Maderuelo</a></dt>
        <dd class="soporte">Fresco painting on mural transferred to canvas. XII century</dd>
        <dd class="autor"><a href="https://www.museodelprado.es/en/the-collection/art-works?cidoc:p14_carried_out_by@@@pm:author@@@ecidoc:p131_E82_p102_has_title=anonymous@en">Anonymous</a>
        </dd>
        <p> The mural paintings from the Hermitage of the Vera Cruz de Maderuelo were transferred to canvas in 1947 and reconstructed at the Prado Museum in a layout as faithful to the original as possible. The w <span class="mas-info">[<span><a href="https://www.museodelprado.es/en/the-collection/art-work/the-creation-of-adam-the-hermitage-of-the-vera/52e8a064-dfad-43db-a9f9-939eeba21869">+</a></span>]</span>
        </p>
      </dl>
    </figcaption>
  </figure>
</div>