简体   繁体   English

jQuery Ajax和AddThis社交书签应用程序

[英]jQuery Ajax and AddThis social bookmark application

I am developing a website that has an AddThis Integration 我正在开发一个具有AddThis集成的网站

Here's my situation right now, 这是我现在的情况

Every time a user inputs an RSS Feed in a text input, it will display the results in the same page since I'm using an AJAX on fetching the data. 每次用户在文本输入中输入RSS Feed时,由于我在获取数据时都使用AJAX,因此它将在同一页面中显示结果。 Together with the result is the AddThis code that has javascripts in it. 与结果一起的是其中包含JavaScript的AddThis代码。 My problem here is the AddThis button is not appearing when I started using AJAX. 我的问题是开始使用AJAX时没有出现AddThis按钮。 But before using that one, it works perfectly. 但是在使用那个之前,它可以完美地工作。

Here's the code. 这是代码。

<div id="entry-form">
        <table>
            <tr>
                <td>Insert RSS Feed Here:</td>
                <td><input type="text" name="url" id="url" style='width:300px;' /></td>
            </tr>
        </table>
    <input type='button' name='submit' value='Submit' class='submit' />
    <div class='urlResult' style='background-color:white; width:75%;'></div>

    </div>

When the user clicks on the button it runs on this jQuery script: 当用户单击按钮时,它将在以下jQuery脚本上运行:

jQuery('.submit').click(function() {
        if( jQuery('#url').val() == "" )
            return false;
        jQuery.ajax({
            type:   "POST",
            url:    "parse.php",
            data:   "url="+jQuery('#url').val(),
            success: function(data) {
                jQuery(".urlResult").html(data);
            }
        });
    });

This is the parse.php file/code: 这是parse.php文件/代码:

<?php
$file = $_POST['url'];

$xml = simplexml_load_file($file,'SimpleXMLElement',LIBXML_NOCDATA);

foreach($xml as $key)
{

    $links = $key->item;

    for($x=0; $x<count($links); $x++) 
    { 
        echo "<pre>";
        echo $links[$x]->link;
        echo "</pre>";
?>

        <!-- AddThis Button BEGIN -->
        <div class="addthis_toolbox addthis_default_style ">
        <a class="addthis_button_preferred_1"></a>
        <a class="addthis_button_preferred_2"></a>
        <a class="addthis_button_preferred_3"></a>
        <a class="addthis_button_preferred_4"></a>
        <a class="addthis_button_compact"></a>
        <a class="addthis_counter addthis_bubble_style"></a>
        </div>
        <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4e6622545c73a715"></script>
        <!-- AddThis Button END -->

    <?php
    }
}           
    ?>

The problem here is that this code is not appearing since I started to use jquery-ajax: This code allows the display of the addThis buttons. 这里的问题是,自从我开始使用jquery-ajax以来,此代码就没有出现:此代码允许显示addThis按钮。

  <div class="addthis_toolbox addthis_default_style ">
            <a class="addthis_button_preferred_1"></a>
            <a class="addthis_button_preferred_2"></a>
            <a class="addthis_button_preferred_3"></a>
            <a class="addthis_button_preferred_4"></a>
            <a class="addthis_button_compact"></a>
            <a class="addthis_counter addthis_bubble_style"></a>
            </div>
            <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4e6622545c73a715"></script>

The javascript files that were embedded on my site is only the jQuery script. 我网站上嵌入的javascript文件只是jQuery脚本。

这篇文章解决了我的问题-您需要通过$ .getScript()动态加载脚本: http ://kb.jaxara.com/how-initialize-addthis-social-sharing-widgets-loaded-ajax

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

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