2017-06-02 62 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>