Skip to content

Instantly share code, notes, and snippets.

@kidchenko
Last active December 23, 2015 02:09
Show Gist options
  • Save kidchenko/6564690 to your computer and use it in GitHub Desktop.
Save kidchenko/6564690 to your computer and use it in GitHub Desktop.
Exemplo de uma chamada ajax sem seletores de elementos entre as funlçoes ajax.
function Tour(el) {
var tour = this;
this.el = el;
this.fetchPhotos = function() {
$.ajax('/photos.html', {
data: {location: tour.el.data('location')},
context: tour,
success: function(response) {
this.el.find('.photos').html(response).fadeIn();
},
error: function() {
this.el.find('.photos').html('<li>There was a problem fetching the latest photos. Please try again.</li>');
},
timeout: 3000,
beforeSend: function() {
this.el.addClass('is-fetching');
},
complete: function() {
this.el.removeClass('is-fetching');
}
});
}
this.el.on('click', 'button', this.fetchPhotos);
}
$(document).ready(function() {
var paris = new Tour($('#paris'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment