Created
July 24, 2015 17:30
-
-
Save code-for-coffee/978fe2ca3ab4e0d0c7f7 to your computer and use it in GitHub Desktop.
Uisng getJSON on an ERB page on the same server
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
<section> | |
<h2>Thanks for visiting!</h2> | |
<p class='stuff'> | |
</p> | |
</section> | |
<script type='text/javascript'> | |
// url to same path on server... | |
// so... '/api/stuff' | |
// maps to... get '/api/stuff' do.... | |
$.getJSON('/api/stuff', function(data) { | |
// data should be data from server | |
// {name: 'James', age: '31'} | |
$('.stuff).append(data.name + ' is ' + data.age + ' years old'); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment