简体   繁体   English

Tripadvisor小部件无法在Ajax页面加载中加载

[英]Tripadvisor widget fails to load on ajax page loading

I am trying to add a Tripadvisor widget (rave) to my page which is loaded via Ajax. 我试图将Tripadvisor小部件(rave)添加到通过Ajax加载的页面中。 Here is the widget code: 这是小部件代码:

<div id="TA_cdsscrollingravewide869" class="TA_cdsscrollingravewide">
    <ul id="1NcDZBZ" class="TA_links 8dTZRew">
    <li id="ZweVlS" class="3cqMCWiB">Read 37 reviews of <a target="_blank" href="http://www.tripadvisor.com/Restaurant_Review-g188590-d946177-Reviews-Bond-Amsterdam_North_Holland_Province.html" onclick="ta.cds.handleTALink($cdsConfig.getMcid()); return true;">Bond</a></li>
    </ul>
    </div>
    <script src="http://www.jscache.com/wejs?wtype=cdsscrollingravewide&amp;uniq=869&amp;locationId=946177&amp;lang=en_US&amp;border=true&amp;shadow=true&amp;backgroundColor=white"></script>

Only when the page loads the first time it's get rendered. 仅在页面首次加载时才呈现。 But after an ajax load it doesn't. 但是在ajax加载之后就没有。

I tried to use jQuery's getScript function but it doesn't help. 我尝试使用jQuery的getScript函数,但没有帮助。 Even manually deleting the added script en link nodes from the head before executing the script again doesn't help. 即使在再次执行脚本之前从头部手动删除添加的脚本en link节点也无济于事。

Can anyone help me fixing this please? 谁能帮我解决这个问题?

The solution: 解决方案:

$.getScript('//www.tripadvisor.fr/WidgetEmbed-selfserveprop?nreviews=6&uniq=&iswide=true&locationId=' + tid + '&rating=true&popIdx=true&border=false&writereviewlink=true&lang=fr', function() {
    if (typeof(window.taValidate) != 'undefined') {
      window.taValidate();
    }
  });

Perhaps the html iframe is a method. 也许html iframe是一种方法。

ex. 恩。

<iframe src="tripadvisor.php" scrolling="no" frameborder="0"></iframe>

tripadvisor.php tripadvisor.php

<div id="TA_cdsscrollingravewide869" class="TA_cdsscrollingravewide">
<ul id="1NcDZBZ" class="TA_links 8dTZRew">
<li id="ZweVlS" class="3cqMCWiB">Read 37 reviews of <a target="_blank" href="http://www.tripadvisor.com/Restaurant_Review-g188590-d946177-Reviews-Bond-Amsterdam_North_Holland_Province.html" onclick="ta.cds.handleTALink($cdsConfig.getMcid()); return true;">Bond</a></li>
</ul>
</div>
<script src="http://www.jscache.com/wejs?wtype=cdsscrollingravewide&amp;uniq=869&amp;locationId=946177&amp;lang=en_US&amp;border=true&amp;shadow=true&amp;backgroundColor=white"></script>

A far from optimal solution which I had to adopt in a similar scenario was based on the following logic: 我在类似情况下必须采用的最佳解决方案远非基于以下逻辑:

Invoke the tripavisor script just once and load the widget inside an hidden html element on whathever page the user lands (so the page is not rendered by an ajax request). 只需调用一次tripavisor脚本,然后将小部件加载到用户登陆的任何页面上的隐藏html元素内(这样该页面就不会由ajax请求呈现)。

When the page where you want the widget placed is called by ajax, if the request is successfully completed, check if the widget is already in DOM, clone it and inject or append it to the ajax generated piece of html. 当ajax调用要放置窗口小部件的页面时,如果请求成功完成,请检查窗口小部件是否已在DOM中,将其克隆并将其注入或附加到ajax生成的html片段中。

I found another solution. 我找到了另一个解决方案。 If you have the widget HTML on the page, or if you added it via jQuery to the page, eg this one: 如果页面上有小部件HTML,或者您是通过jQuery将其添加到页面的,例如:

<div id="TA_cdsscrollingravewide869" class="TA_cdsscrollingravewide">
<ul id="1NcDZBZ" class="TA_links 8dTZRew">
<li id="ZweVlS" class="3cqMCWiB">Read 37 reviews of <a target="_blank" href="http://www.tripadvisor.com/Restaurant_Review-g188590-d946177-Reviews-Bond-Amsterdam_North_Holland_Province.html" onclick="ta.cds.handleTALink($cdsConfig.getMcid()); return true;">Bond</a></li>
</ul>
</div>

you can execute this script below, and it will load the widget: 您可以在下面执行此脚本,它将加载小部件:

$.getScript("https://www.tripadvisor.com/WidgetEmbed-cdsscrollingravewide", function(){
    if (typeof(window.taValidate) != 'undefined') {
      window.taValidate();
    }
});

Please note that for example in my case the widget class is TA_ cdsratingsonlynarrow , so for me the script URL looks like this: 请注意,例如,在我的情况下,小部件类为TA_ cdsratingsonlynarrow ,因此对我而言,脚本URL如下所示:

https://www.tripadvisor.com/WidgetEmbed-cdsratingsonlynarrow

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM