1

I keep on getting this error in my page when I call the API in ajax request. I checked same thing in another question but did not get the proper result for my page.Please someone help me with the answers you know.Here is my code that calls the Api through ajax request:

function getIP() { 
  var bat=$('#battery').val();
  var id="<?=$_SESSION["id"]?>";
  var myip="<?=get_client_ip()?>";
  $.ajax({
        type: "post",
        url: 'map.php',
        data: {ip: myip,bat:bat,id:id},
        success: function(data){
            console.log(data);
        }
    });
 }

and the page called has the fallowing code:

<?php
include('includes/connect.php');
$id = $_POST['id'];
$PublicIP = $_POST['ip'];
$battery = $_POST['bat'];
$json     = file_get_contents("https://ipinfo.io/$PublicIP/geo");
 //echo($json);
$json     = json_decode($json, true);
$country  = $json['country'];
$region   = $json['region'];
$city     = $json['city'];
$postal   = $json['postal'];
$loc=$json['loc'];
?>

Please someone help me to get the proper result.This code works in my local but not in my server.I refered this also https://stackoverflow.com/questions/50873764/cross-origin-read-blocking-corb but did not get proper result for mine.Please someone help me.

pukka
  • 45
  • 6

1 Answers1

1

Try like this:

$json = file_get_contents("https://ipinfo.io/".$PublicIP."/geo");
Raazim
  • 26
  • 3