Skip to content

Instantly share code, notes, and snippets.

@lnmunhoz
Last active May 1, 2017 22:08
Show Gist options
  • Save lnmunhoz/6504537 to your computer and use it in GitHub Desktop.
Save lnmunhoz/6504537 to your computer and use it in GitHub Desktop.
You've decided you only want to get photos of london. Use the data option of the $.ajax function to pass a location option. Get the location from the data-location on the #tour element using the data method.
DOM :
<div id="tour" data-location="london">
<button>Get Photos</button>
<ul class="photos">
</ul>
</div>
JS:
$(document).ready(function() {
var el = $("#tour")
el.on("click", "button", function() {
$.ajax('/photos.html', {
data: {location: el.data('location')},
success: function(response) {
$('.photos').html(response).fadeIn();
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment