How to call outside API's on Hubl language

Highlighted
Occasional Contributor

How to call outside API's(http://ip-api.com/json/182.72.242.178) on Hubl language 

I wrote the code below.But it's not working

{% set ipadress="~ curl http://ip-api.com/json/182.72.242.178" %}

Reply
0 Upvotes
2 Replies 2
Regular Advisor

Hi @prasadcolumbus 

you can write Ajax code with JavaScript code, like this

 

<script>
  $(document).ready(function() {
     function ipLookUp() {
    $.ajax('https://ipapi.co/json/')
        .then(
            function success(response) {
                var country = response.country_name.split(' ').join('_').toLowerCase();
                alert(country)
              //if you need class in body
                $('body').addClass(country);
            },

            function fail(data, status) {
                console.log('Request failed.  Returned status of',
                    status);
               
            }
        );
}
ipLookUp();
  });
</script>

Demo - http://bit.ly/30cgOqt

------------------------------------------------------------------

Did our post help answer your query? Help the Community by marking it as a solution.

Team TRooInbound

 

For more information please visit our website or mail us at hello@trooinbound.com

Reply
0 Upvotes
Occasional Contributor

Without jQuery is their any possiblity way to call API threw Hubl language?

 

I am having some issues on using jQuery to load the content