Getjson查询不工作

getjson query is not working

本文关键字:工作 查询 Getjson      更新时间:2023-09-26

Json页面为:http://freegeoip.net/json/59.92.78.49

我的代码是

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

这个简单的代码不能工作:(

似乎freegeoip.net支持jsonp,你可以这样做:

$('button').click(function () {
    $.ajax({
        url: "http://freegeoip.net/json/59.92.78.49",
        dataType: "jsonp",
        success: function (result) {
            alert(result.ip); // server response
        }
    });
});
<<p> 小提琴演示/strong>