简体   繁体   English

Facebook共享按钮似乎无法在使用Javascript和Ajax的Webmethod中使用

[英]Facebook share button doesn't seem to work in a Webmethod with Javascript and Ajax

I'm trying to use Facebook share button on a list of photos where each photo has its own button with a different URL. 我正在尝试在照片列表中使用Facebook共享按钮,其中每张照片都有其自己的按钮,并带有不同的URL。 Unfortunately I can't make this work. 不幸的是我无法完成这项工作。 I get all the testing strings except the facebook button string. 我得到了除Facebook按钮字符串之外的所有测试字符串。 To test whether the facebook SDK works I removed the string from the webmethod and add it directly on my aspx page. 为了测试facebook SDK是否有效,我从web方法中删除了字符串,并将其直接添加到我的aspx页面上。 Then it worked! 然后成功了! But I want to have it in the Webmethod as follows... 但我想按如下方式在Webmethod中使用它...

page.aspx (in the body section) page.aspx(在正文部分)

<div id="fb-root"></div>
<script>
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src= "//connect.facebook.net/fr_FR/sdk.js#xfbml=1&appId=**************&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

[WebMethod]
public static string photo()
{
StringBuilder photo_sb = new StringBuilder();
var photo_query = db.Query("SELECT * FROM [photos]);
foreach (var item in photo_query )
{
photo_sb.Append("Testing"); // I get this string
photo_sb.Append("<div class=\"fb-share-button\" data-href=\"http://********.com/photos.aspx?IDphoto=" + item.IDphoto + "\" data-layout=\"icon\"></div><br />"); // I don't get this string
photo_sb.Append("Testing2"); // I get this string
}
return photo_sb.ToString();
}

Script 脚本

function Load() {
$.ajax({
            type: "POST",
            url: "UserControls.aspx/photo",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) { if (data.d != "") { $('.photoList').append(data.d);}

... ...

Use the following code to Share 使用以下代码共享

<iframe src="//www.facebook.com/plugins/share_button.php?href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&amp;layout=button_count" scrolling="no" frameborder="0" style="border:none; overflow:hidden;" allowTransparency="true"></iframe>

and to sepcify 并区分

<meta property="og:title" content="YOUR TITLE HERE" />
<meta property="og:description" content="YOUR DESCRIPTION HERE" />
<meta property="og:image" content="YOUR THUMBNAIL URL HERE" />

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

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