Hello,
On page load, I do one call to get the current status of all the favourite links (display the right message aka: click to subscribe, click to unsubscribe.
Final Code! :) Thanks for your help guys, please check post revisions to see the issue.
$(InitFavorite);
function InitFavorite(){
var jList = $(".favourite_link");
var ids_to_check = {};//new Array();
$.each(jList, function () {
var id = this.id;
var object = id.split("_");
if (!ids_to_check[object[1]]) {
ids_to_check[object[1]] = [];
}
ids_to_check[object[1]].push(object[0]);
});
$.ajax({
type: 'POST',
url: '/user/subscription/favourite-listing',
data: ids_to_check,
dataType: 'json',
beforeSend: function(x) {
if(x && x.overrideMimeType) {
x.overrideMimeType("application/json;charset=UTF-8");
}
},
error: function() {
//could not load favourites
},
success: function(returned_values) {
$.each(returned_values.favourites.Clip, function(i, item) {
$('#'+i+'_Clip').html(''+item+'');
});
$.each(returned_values.favourites.Playlist, function(i, item) {
$('#'+i+'_Playlist').html(''+item+'');
});
}
});