Skip to content

Instantly share code, notes, and snippets.

@code-for-coffee
Created July 24, 2015 17:30
Show Gist options
  • Save code-for-coffee/978fe2ca3ab4e0d0c7f7 to your computer and use it in GitHub Desktop.
Save code-for-coffee/978fe2ca3ab4e0d0c7f7 to your computer and use it in GitHub Desktop.
Uisng getJSON on an ERB page on the same server
<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