Skip to content

Commit

Permalink
adding basic ajax demo to api page
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Bewick committed Jan 29, 2012
1 parent 6957d71 commit 1c4f9d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion application/views/api/index.php
Expand Up @@ -6,9 +6,10 @@
<h2>API</h2>
<hr />
<h3>What are you after?</h3>
<ul>
<ul id="api-links">
<li>Get the 2 latest artists as JSON = <?php echo anchor('/api/artists/2', '/api/artists/2'); ?></li>
<li>Get the artist with id 2 as JSON = <?php echo anchor('/api/artist/2', '/api/artist/2'); ?></li>
</ul>
<pre><code id="result">Results of API call will be loaded here...</code></pre>
</div>
</div>
15 changes: 14 additions & 1 deletion application/views/templates/footer.php
Expand Up @@ -11,6 +11,19 @@
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script src="<?= base_url(); ?>/js/explore.js"></script></script>
<?php } ?>

<?php if($this->uri->segment(1)=="api"){ ?>
<script>
$(function(){
$('#api-links a').on('click',function(e){
e.preventDefault();
var url = this.href;
$('#result').text('Loading...');
$.getJSON(url, function(data) {
$('#result').text(JSON.stringify(data));
});
});
});
</script>
<?php } ?>
</body>
</html>

0 comments on commit 1c4f9d4

Please sign in to comment.