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>

Reference

  1. http://delicious.com/help/feeds
  2. http://api.jquery.com/jQuery.getJSON/

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
3 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
4 Comment authors
Youssef Daharayalcinkayacheckerrupam Recent comment authors
newest oldest most voted
Youssef Dahar
Guest
Youssef Dahar
checker
Guest
checker

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.

ayalcinkaya
Guest
ayalcinkaya

I get “Delicious count : 21172 Saved” for the URL: http://www.google.com

Are you sure your browser support ajax ?

rupam
Guest
rupam

thank you man .i need this very much .