Question

Json page is : http://freegeoip.net/json/59.92.78.49

and my code is

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
       </script>
       <script>
       $(document).ready(function(){
        $("button").click(function(){
          $.getJSON("http://localhost/02/t.php",function(result){
                     alert(result.ip);
             });            
             });
           });
         </script>

this simple code is not working :(

Était-ce utile?

La solution

Seem like freegeoip.net support jsonp,you can do:

$('button').click(function () {
    $.ajax({
        url: "http://freegeoip.net/json/59.92.78.49",
        dataType: "jsonp",
        success: function (result) {
            alert(result.ip); // server response
        }
    });
});

Fiddle Demo

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top