-
-
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.
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
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