0

I have 2 functions, one that looks up the users IP address and another that finds information based off of that. The first I have like this:

<script type="application/javascript">
  function getIP(json) {
    console.log(json.ip)
  }
</script>
<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script>
and the second looks like this:

<script>
  function getLocation(json) {
    console.log(json.region);
  }
</script>

<script type="application/javascript" src="https://json.geoiplookup.io/"+ IPADDRESS +"?callback=getInfo" id="test"></script>

Where the second ones script tag has IPADDRESS I need the IP address from the first to be if I use document.getElementById() it has to be above the script which is not allowed. Is there a way I can just define a variable and then use it as I have with IPADDRESS

  • Does this answer your question? [How to make a JSONP request from Javascript without JQuery?](https://stackoverflow.com/questions/6132796/how-to-make-a-jsonp-request-from-javascript-without-jquery) – Ivar Nov 22 '20 at 11:12

1 Answers1

0

I don't think it's possible instead I realised that the API I was using could run from the users IP address, giving me this:

    <script type="application/javascript">
      function getIP(json) {
        console.log(json.ip);
        console.log(json.city);
      }
    </script>
    <script type="application/javascript" src="https://json.geoiplookup.io?callback=getIP"></script>

Discovered this accidentally