jQuery Ajax 和 AddThis 社交书签应用程序
我正在开发一个具有 AddThis 集成的网站
这是我现在的情况,
每次用户输入 RSS 提要时在文本输入中,它将在同一页面中显示结果,因为我使用 AJAX 来获取数据。与结果一起的是包含 javascript 的 AddThis 代码。 我的问题是当我开始使用 AJAX 时,AddThis 按钮没有出现。但在使用之前,它工作得很好。
这是代码。
<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>
当用户单击按钮时,它会在以下 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);
}
});
});
这是 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
}
}
?>
这里的问题是,自从我开始使用 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>
我的网站上嵌入的 javascript 文件只是 jQuery 脚本。
I am developing a website that has an AddThis Integration
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. Together with the result is the AddThis code that has javascripts in it.
My problem here is the AddThis button is not appearing when I started using AJAX. 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('.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:
<?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.
<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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这篇文章解决了我的问题——您需要通过 $.getScript() 动态加载脚本:
http://kb.jaxara.com/how-initialize -addthis-social-sharing-widgets-loaded-ajax
This post solved my issue -- you need to dynamically load in the script via $.getScript():
http://kb.jaxara.com/how-initialize-addthis-social-sharing-widgets-loaded-ajax