How to get Delicious bookmark count with jQuery and JSON
Delicious, the best bookmark website, provides many APIs to let developers to deal with the bookmarks’ data. Here’s an example to use jQuery to retrieve the total number bookmark count of a given URL.
Delicious API
To get a total number of bookmark, use this
http://feeds.delicious.com/v2/json/urlinfo/data?url=xxx.com&callback=?
jQuery Ajax
jQuery, comes with an easy but powerful .ajax() or shorthand .getJSON() to get the remote data on demand.
1. jQuery .ajax() example
Use the jQuery .ajax() to get the json data from Delicious, and display the total number of the bookmark count.
$.ajax({
type: "GET",
dataType: "json",
url: "http://feeds.delicious.com/v2/json/urlinfo/data?url="+url+"&callback=?",
success: function(data){
var count = 0;
if (data.length > 0) {
count = data[0].total_posts;
}
$("#delicious_result").text(count + ' Saved');
}
});
2. jQuery .getJSON() example
Shorthand for the above .ajax() method, both are doing the same task.
$.getJSON("
http://feeds.delicious.com/v2/json/urlinfo/data?url="+url+"&callback=?",
function(data) {
var count = 0;
if (data.length > 0) {
count = data[0].total_posts;
}
$("#delicious_result").text(count + ' Saved');
});
Try it yourself
In this example, type the URL into the text box and click on the button to get the total number of bookmark in Delicious.
<html>
<head>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
</head>
<body>
<h1>Get Delicious bookmark count with jQuery</h1>
URL : <input type='text' id='url' size='50' value='http://www.google.com' />
<br/><br/>
<h2>Delicious count : <span id="delicious_result"></span></h2>
<button id="delicious">Get Delicious Count (.Ajax)</button>
<button id="delicious2">Get Delicious Count (.getJSON)</button>
<script type="text/javascript">
$('#delicious').click(function(){
$("#delicious_result").text("Loading......");
var url = $('#url').val();
$.ajax({
type: "GET",
dataType: "json",
url: "http://feeds.delicious.com/v2/json/urlinfo/data?url="+url+"&callback=?",
success: function(data){
var count = 0;
if (data.length > 0) {
count = data[0].total_posts;
}
$("#delicious_result").text(count + ' Saved');
}
});
});
$('#delicious2').click(function(){
$("#delicious_result").text("Loading......");
var url = $('#url').val();
$.getJSON("
http://feeds.delicious.com/v2/json/urlinfo/data?url="+url+"&callback=?",
function(data) {
var count = 0;
if (data.length > 0) {
count = data[0].total_posts;
}
$("#delicious_result").text(count + ' Saved');
});
});
</script>
</body>
</html>
i nedd code source of http://feeds.delicious.com/v2/json/urlinfo/data?url=xxx.com&callback=? page if its possible
When I happened to test the above code, in this site, I always get a result of zero.
Is there any change in the API? or if the code works fine please suggest me a url to test.
Please Help me. ASAP.
Thank You.
I get “Delicious count : 21172 Saved” for the URL: http://www.google.com
Are you sure your browser support ajax ?
thank you man .i need this very much .