我怎样才能让像'Digg它'一个按钮,我的网站? [英] How can I make a button like 'Digg it' for my website?

查看:166
本文介绍了我怎样才能让像'Digg它'一个按钮,我的网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有托管在Windows Sever的,ASP.Net 3.5,ASP.Net AJAX,SQL Server中的背景。

一个博客网站

我想给博主喜欢'Digg的,这是一个按钮,就可以把自己的博客的读者点击拇指起来后,如果他们喜欢它。

我知道我将使用JavaScript来做到这一点。我能做些什么来: -

  1. 从我的网站code,这将显示拇指向上当前计数。
  2. 增加计数在我的网站,如果用户赞许的东西。

由于大多数的这些博客都在blogger.com/word$p$pss.com,插件code将被嵌入到博客的主题。我想我会用博客文章作为唯一ID的URL。我的问题是如何让我的网站和JavaScript是在blogger.com上说话。

您的帮助将是AP preciated。

感谢

解决方案

您可以考虑使用脚本回调加载JSON数据,而不是使用XmlHtt prequest,以绕过跨域问题。

 函数dynScript(URL){
    VAR脚本= document.createElement方法(脚本);
    script.src =网址;
    script.type =文/ JavaScript的;
    document.getElementsByTagName(头)[0] .appendChild(脚本);
}
功能handleYourData(JSON){
    //做一些与你的响应数据,如果你需要,像ALTER
    // DOM。
}
功能thumbUp(postId){
    dynScript('http://yourdomain.com/path/to/thumbHandler?callback=handleYourData&thumbs=up&postId=' + postId);
}
功能thumbDown(postId){
    dynScript('http://yourdomain.com/path/to/thumbHandler?callback=handleYourData&thumbs=down&postId=' + postId);
}
 

您可以使用它像这样在你的HTML。

 <一个的onClick =thumbUp(521);>拇指向上LT; / A> | &其中;一个的onClick =thumbDown(521);>拇指唐氏所述; / a取代;
 

thumbHandler code将不得不输出JSON与 handleYourData()包裹着它,这样你回调将被调用,使用JSON数据作为参数。<​​/ P>

I've got a blogging site hosted on Windows Sever, ASP.Net 3.5, ASP.Net AJAX, SQL Server in background.

I want to give bloggers a button like 'digg-it' which they can put on their blogs for the readers to click to thumb-up the post if they like it.

I know I'll be using Javascript to do that. What can I do to: -

  1. Retrieve code from my website which will display the current count of the thumb-up.
  2. Increase the count on my website if the user thumbs up something.

Since most of these blogs are on blogger.com/wordpress.com, the plugin code will be embedded in the blog theme. I guess I will be using the URL of the blog post as the unique id. My problem is how to get my site and javascript that's on blogger.com talking.

Your help will be appreciated.

Thanks

解决方案

You can look into using SCRIPT callbacks loading JSON data instead of using XmlHttpRequest to get around the crossdomain issues.

function dynScript(url){
    var script=document.createElement('script');
    script.src=url;
    script.type="text/javascript";
    document.getElementsByTagName('head')[0].appendChild(script);
}
function handleYourData(json) {
    // Do something with your response data if you need to, like alter
    // dom.
}
function thumbUp(postId) {
    dynScript('http://yourdomain.com/path/to/thumbHandler?callback=handleYourData&thumbs=up&postId=' + postId);
}
function thumbDown(postId) {
    dynScript('http://yourdomain.com/path/to/thumbHandler?callback=handleYourData&thumbs=down&postId=' + postId);
}

You can use it like this in your HTML.

<a onClick="thumbUp(521);">Thumb up</a> | <a onClick="thumbDown(521);">Thumb Down</a>

Your thumbHandler code would have to output JSON with handleYourData() wrapped around it so that your callback will be called with the JSON data as the argument.

这篇关于我怎样才能让像'Digg它'一个按钮,我的网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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