Created
October 18, 2013 13:20
-
-
Save CNSam/7041455 to your computer and use it in GitHub Desktop.
Shortlist - Add Item jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('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