$(document).ready(function () {
var user = 1;
$("a.like").on("click", function () {
var article = $(this).attr('data-article');
$.ajax({
type: "POST",
url: "WebService.asmx/Like",
data: "{ 'user': '" + user + "', 'article': '" + article + "' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
if(msg.d == 1)
{
$(".like[data-article='" + article + "']").fadeOut(700).addClass('unlike').removeClass('like').stop().text('Unlike').fadeIn(700);
}
},
failure: function (msg) {
alert(msg.d);
}
});
});
$("a.unlike").on("click", function () {
var article = $(this).attr('data-article');
$.ajax({
type: "POST",
url: "WebService.asmx/Unlike",
data: "{ 'user': '" + user + "', 'article': '" + article + "' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
if(msg.d == 1)
{
$(".unlike[data-article='" + article + "']").fadeOut(700).addClass('like').removeClass('unlike').stop().text('Like').fadeIn(700);
}
},
failure: function (msg) {
alert(msg.d);
}
});
});
});
Clicking on a link with class like or unlike works as expected, but it does not work when the same link is clicked twice. Research suggests using live instead of click, however live is deprecated as of version 1.8. How can I ensure this function can be triggered multiple times?