Created
January 3, 2015 21:07
-
-
Save gamerlv/4eb901e375f49219477b to your computer and use it in GitHub Desktop.
Little drop in example, Out of the top of my head but should work
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
//Any element with a class of voteBtn will trigger this, it can ba a button, a <a>, a <div> you name it | |
//As long as it has the data attribute | |
$('.voteBtn').click(function(e){ | |
var $that = $(this); | |
$.post('/url/where/data/is/sendTo.php', {category_id: $that.data('category-id')}, function(data){ | |
if (data.result){ //data needs to be valid json: {result: true} | |
$that.text("Voted!").attr('disabled', 'disabled'); | |
} else { | |
$that.text("Try again later, something broke").attr('disabled', 'disabled'); | |
setTimeout(function(){ $that.removeAttr('disabled') }, 2000); | |
} | |
}); | |
//Don't do what ever it is that you normally do | |
e.preventDefault(); | |
//DON'T RETURN FALSE. THAT'S DEPECRATED WEB 2 SHIT | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment