Skip to content

Instantly share code, notes, and snippets.

@CNSam
Created October 18, 2013 13:20
Show Gist options
  • Save CNSam/7041455 to your computer and use it in GitHub Desktop.
Save CNSam/7041455 to your computer and use it in GitHub Desktop.
Shortlist - Add Item jQuery
$('a.shortlist_action.available').on('click', function(){
// Assign variable
thisFlag = $(this);
modal = $(thisFlag).parent().parent().find('.modal-item');
$(modal).slideToggle();
$(document).one('click', function(){
$(modal).fadeOut();
});
$('.modal-item a').on('click', function(){
triggerurl = $(this).attr('href');
$.ajax({
url: triggerurl,
contentType: "application/json; charset=utf-8",
dataType: "json",
complete: function(data) {
console.log('success');
// Setting up variables
type = data['type'];
toggle_url = data['toggle_url'];
total_number = data['total_items'];
// Lets work out if it's been added
$(thisFlag).addClass('active');
$(thisFlag).attr('href', toggle_url);
$('#main-navigation .count').text('('+total_number+')');
$(modal).fadeOut();
},
error: function(jqxhr) {
console.log(jqxhr.responseText); // @text = response error, it is will be errors: 324, 500, 404 or anythings else
}
});
return false;
});
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment