Created
March 18, 2016 17:50
-
-
Save fgbreel/956d9041dba25afd295c to your computer and use it in GitHub Desktop.
JS ajax background loader
This file contains hidden or 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
var post = { | |
init: function() { $('.post').on('click', this.loadPost); }, | |
updatePost: function(result, event) { | |
var $post = $(event.currentTarget); | |
$post.fadeIn({ | |
duration: 400, | |
start: function(){ | |
$post.find('.post-title').text(result.title); | |
$post.find('.post-content').text(result.content); | |
$post.find('.post-category').text(result.category); | |
$post.find('.post-meta').text(); | |
} | |
}); | |
}, | |
loadPost: function(event) { | |
$.ajax('recent', { | |
dataType: 'json', | |
timeout: 4000, | |
success: function(result) { post.updatePost(result, event) }, | |
error: function(request, errorType, errorMessage) { | |
alert('Error: ' + errorType + ' with message: ' + errorMessage); | |
}, | |
beforeSend: function(){ | |
$(event.currentTarget).fadeOut(); | |
}, | |
}); | |
} | |
} | |
$(document).ready(function() { | |
post.init(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment