문제

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 :(

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top