dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Javascript to retrieve current exchange rate

  1. #1
    Join Date
    Feb 2017
    Posts
    3

    Javascript to retrieve current exchange rate

    Hi,

    I'm trying to use javascript to retrieve the current exchange rate between USD and bitcoin.

    I've followed a few online examples but can't get any of them to work - probably because I'm not really familiar enough with javascript and am making some basic mistake.

    Can anyone advise how I can do this? Or what the pre-requisites are? I've just pasted in the examples I've found into a blank html page - the page displays, and I've added a button that calls the function, but when I click it the javascript doesn't appear to run (I've put an alert as the first thing in the script but it doesn't appear).

    Can anyone help?

    Thanks,

    WP.

  2. #2
    Join Date
    Aug 2016
    Posts
    113
    could you give us the address of these on line examples
    and show us the code you have tried

  3. #3
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    4,727
    I did a search, you can find hundreds of tools and other questions asked by users on many other sites.

    Yahoo and Google provide tools for this purpose, so maybe you want to look in to scraping both or doing further research in to where you can scrape curreny data from.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  4. #4
    Join Date
    Feb 2017
    Posts
    3
    Hi,

    Thanks for your replies.

    The most recent example of what I'm doing is taken from currencylayer.com - I've set up a basic (free) account, just to get an access key so that I can try and figure this out.

    They have a script on their site as follows:


    // set endpoint and your access key
    endpoint = 'live'
    access_key = 'YOUR_ACCESS_KEY';

    // get the most recent exchange rates via the "live" endpoint:
    $.ajax({
    url: 'http://apilayer.net/api/' + endpoint + '?access_key=' + access_key,
    dataType: 'jsonp',
    success: function(json) {

    // exchange rata data is stored in json.quotes
    alert(json.quotes.USDGBP);

    // source currency is stored in json.source
    alert(json.source);

    // timestamp can be accessed in json.timestamp
    alert(json.timestamp);

    }
    });


    I've entered my access key where it shows 'YOUR ACCESS KEY', and enclosed the code shown above in <script> and </script> tags, but I get no alerts when I display the page in my browser.

    Am I on the right track at all, or am I way off?!


    Thanks,
    WP.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles