Skip to content

Instantly share code, notes, and snippets.

@cafuego
Last active December 24, 2015 23:09
Show Gist options
  • Save cafuego/6878417 to your computer and use it in GitHub Desktop.
Save cafuego/6878417 to your computer and use it in GitHub Desktop.
$('#element').replaceWith('<div id="element">Reloading...</div>');
$.ajax({
type: 'POST',
url: '/js/element-callback',
dataType: 'json',
success: function (data) {
if (data.element) {
// Push the result into the wrapper div.
$('#element').replaceWith('<div id="element">' + data.element + '</div>');
}
else {
$('#element').replaceWith('<div id="element"></div>');
}
},
error: function (xmlhttp) {
$('#element').replaceWith('<div id="element">An error occured: ' + xmlhttp.status + '</div>');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment