Skip to content

Instantly share code, notes, and snippets.

@cflove
Created March 15, 2014 01:58
Show Gist options
  • Select an option

  • Save cflove/9560775 to your computer and use it in GitHub Desktop.

Select an option

Save cflove/9560775 to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="en">
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<meta charset="UTF-8">
<title>Ajax Call</title>
<style type="text/css">
body {font-family: Verdana; font-size: 14px}
.rabbits {cursor: pointer; color: red;}
#AboutRabbits {padding: 20px;}
</style>
</head>
<body>
Meet our Rabbits :
<span class="rabbits" data-url="Peter">Peter</span> .
<span class="rabbits" data-url="Benjamin">Benjamin Bunny</span> .
<span class="rabbits" data-url="Cotton-Tail">Cotton-Tail</span> .
<span class="rabbits" data-url="Mrs-Rabbit">Mrs. Rabbit</span>
<div id="AboutRabbits">Click On Rabbit's Name to See More</div>
<script type="text/javascript">
$(document).ready(function(){
$('.rabbits').click(function() {
// $('body').on('click','.rabbits', function() {
$.ajax({
url: "http://localhost/"+ $(this).attr('data-url')+'.html'
}).success(function(data) {
$('#AboutRabbits').html(data)
});
})
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment