Skip to content

Instantly share code, notes, and snippets.

@joshuaadrian
Last active December 26, 2015 19:09
Show Gist options
  • Save joshuaadrian/7199457 to your computer and use it in GitHub Desktop.
Save joshuaadrian/7199457 to your computer and use it in GitHub Desktop.
var ajaxTemplate = {
init: function() {
$('.parentElement').on( 'click', '.dynamicChildElement', this.ajaxCall )
},
ajaxCall: function() {
$.ajax('/relative_file_path.php', {
type: "POST", // Defaults to get
data: {
'key' : 'value',
'key' : 'value'
},
success: function(response) {
// Success code here
},
error: function(request, errorType, errorMessage) {
// Error code here
},
timeout: 3000, // Defaults to browser default, so best to set explicitly set it
beforeSend: function() {
// Good place to place loading gif / animation
},
complete: function() {
// Fires after success or error
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment