Jump to content

Output connection from API

Recommended Posts

Site URL: https://www.maestros-online.com

Hi all,

Very new to web design so apologies if this is a basic question. I'm looking to have my site display currencies in plain text on the home page. For now, I just want to be able to fetch the visitor IP and produce a symbol based on the location. IP Stack has a free API that I can use, and looking through the documentation, I assume I need to inject this code into the header script to log in and fetch the Symbol variable:

<script>
  // set endpoint and your access key
var ip = '134.201.250.155'
var access_key = 'APIKEY';

// get the API result via jQuery.ajax
$.ajax({
    url: 'http://api.ipstack.com/' + ip + '?access_key=' + access_key,   
    dataType: 'jsonp',
    success: function(json) {

        // output the "symbol" object inside "currency"
        alert(json.currency.symbol);
        
    }
});
</script>

 

So I have an alert - json.currency.symbol, but how would I then print this in the text? I assume I need to create a source code block, and then do something like:

<script>

var output = document.getelementbyID('output');
output.innerHTML= json.currency.symbol;

</script>

 

Am I anyway near on this?

 

Thanks for the help

Edited by SolidSnake100
right info
Link to comment
  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.