Last active
December 21, 2015 04:19
-
-
Save prasadshir/6248353 to your computer and use it in GitHub Desktop.
jQuery Ajax Basic Example
This file contains 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
[ | |
{ | |
"id":0, | |
"name":"Amitabh Bacchan", | |
"type":"Bollywood", | |
"twitter":"SrBachchan", | |
"desc":"Amitabh is my most favorite hero" | |
}, | |
{ | |
"id":1, | |
"name":"Sachin Tendulkar", | |
"type":"Cricket", | |
"twitter":"sachin_rt" | |
}, | |
{ | |
"id":2, | |
"name":"Deepika Padukon", | |
"type":"Bollywood", | |
"twitter":"deepikapadukone" | |
} | |
] |
This file contains 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
<html> | |
<head> | |
<script src="js/jquery-1.9.1.js"></script> | |
</head> | |
<body> | |
<div id="changeThis">This text will be changed by Ajax</div> | |
<button id="btn">Change Text</button> | |
<button id="btn1">Fetch Data</button> | |
<div id='dynamic'> | |
<h2>Dynamic Data</h2> | |
<ul></ul> | |
</div> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
$("#btn").click(function(){ | |
$("#changeThis").load("textfile.txt"); | |
}); | |
}); | |
$("#btn1").click(function(){ | |
$.ajax({ | |
url: 'heros.json', | |
success: function(herosData){ | |
console.log(herosData); | |
$.each(herosData, function(i,v){ | |
$('#dynamic ul').append('<li>'+v.name+'</li>'); | |
}) | |
} | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains 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
This is sample text from the text file! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment