Tripadvisor小部件无法在Ajax页面加载中加载 [英] Tripadvisor widget fails to load on ajax page loading

查看:90
本文介绍了Tripadvisor小部件无法在Ajax页面加载中加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将Tripadvisor小部件(rave)添加到通过Ajax加载的页面上. 这是小部件代码:

I am trying to add a Tripadvisor widget (rave) to my page which is loaded via 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>

仅在页面首次加载时呈现.但是在ajax加载之后却没有.

Only when the page loads the first time it's get rendered. But after an ajax load it doesn't.

我尝试使用jQuery的getScript函数,但无济于事.即使在再次执行脚本之前从头部手动删除添加的脚本en link节点也无济于事.

I tried to use jQuery's getScript function but it doesn't help. Even manually deleting the added script en link nodes from the head before executing the script again doesn't help.

有人可以帮我解决这个问题吗?

Can anyone help me fixing this please?

推荐答案

在类似情况下,我不得不采用的最佳解决方案远非基于以下逻辑:

A far from optimal solution which I had to adopt in a similar scenario was based on the following logic:

只调用一次tripavisor脚本,然后将小部件加载到用户登陆的任何页面上的隐藏html元素内(这样该页面就不会由ajax请求呈现).

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).

用ajax调用要放置窗口小部件的页面时,如果请求成功完成,请检查窗口小部件是否已在DOM中,将其克隆并将其注入或附加到ajax生成的html中.

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.

这篇关于Tripadvisor小部件无法在Ajax页面加载中加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆