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/>
<h4>Delicious count : <span id="delicious_result"></span></h4>
 
<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+"&amp;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+"&amp;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/
Any Java questions or problems? please post at this JavaNullPointer.com forum, see you there ~
[ Read More ] You can find more similar articles at jQuery Tutorials