icon for lab

CT310

Recitation 17 - AJAX

In this recitation, we will:


You must submit the link to your BitCoin Price Fetch under Lab17 on Canvas.

Asynchronous Javascript and XML

Allows you to reload parts of webpages quickly without reloading the entire thing

Essential for modern web development

Make asynchronous calls to server without waiting for responses

HTML, JavaScript(jQuery), and some CSS.

Uses XML but can also use JSON.

This example also uses bootstrap again.

Use of an API. API's are application programmer interfaces. It allows us to write software that interacts with other applications. In this case we are interfacing with a random dog api to get random images of dogs.

The following example randomly loads dog images from the random dog api https://dog.ceo/dog-api/.
The example can be found at this link: example

You can see the example js file by going to sources and looking at ajaxexample.js

Download the source files here

Most of the code is already written, in the bitcoinpricefetch.js you have to edit it so that it updates the bitcoin price. Everytime the "Get Price Update" button is clicked the updatePrice() function is called.

You can see that update price makes a $.ajax call to the coinbase api. If successful, then you get the exchange rates for USD to all other cryptocurrencies on the exchange. The symbol for bitcoin is BTC.

Complete the code to set the btc_price variable equal to the actual bitcoin price received from the server.

Submit the link to your app on canvas