2017-06-02 97 views
-3

This website当用户向下滚动时,会动态加载内容。向下滚动时,网站会发送一个AJAX请求(如开发工具>网络选项卡中所示),该请求会返回JSON数据。Ajax请求失败,同时网站可以成功创建相同的请求

当我手工制作的要求,无论是browsing to或通过我自己的要求:

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

它返回一个运行时错误。

Server Error in '/' Application. 

Runtime Error 

Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. 

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off". 


<!-- Web.Config Configuration File --> 

<configuration> 
    <system.web> 
     <customErrors mode="Off"/> 
    </system.web> 
</configuration> 

Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL. 


<!-- Web.Config Configuration File --> 

<configuration> 
    <system.web> 
     <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/> 
    </system.web> 
</configuration> 

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

编辑

This image shows the devtools > network

+1

POST请求需要什么14表单参数? –

+0

这是一个帖子请求,但没有一个空的身体 – Andreas

+0

@Satpal相当肯定。我已经添加了devtool输出的视图。 –

回答

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); 
    } 
}); 

结果是有两个参数的一个JSON:KeyValue like

<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:[email protected]@@pm:[email protected]@@ecidoc:[email protected]">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:[email protected]@@pm:[email protected]@@ecidoc:[email protected]">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>