代码为:

$.getScript('http://int.dpool.sina.com/iplookup/iplookup.php?format=js',function(_result){

  if(remote_ip_info.ret=='1'){

     $.ajax({

         type:"GET",

         url:"http://wthrcdn.etouch.cn/weather_mini?city="+remote_ip_info.city,

         data:'',

         success:function(msg){

              console.log(msg);

           }

        });

   }

});

msg为一个字符串,里面包含了城市,5天的天气预报等信息。如果需要在页面进行显示,则在页面获取元素后,通过html()来进行设置内容。msg需要先通过eval()方法或者JSON.parse()方法来转换为JSON对象。然后对msg.data.*获取需要的属性值。如我设置了一个id为a的div,使里面显示天气内容:

var r=eval('('+msg+')');    //也可以使用JSON.parse(msg);
$('#a').html(r.data.city+"   "+r.data.forecast[0].date+r.data.forecast[0].fengli+r.data.forecast[0].high+r.data.forecast[0].low+r.data.forecast[0].type);
console.log(r);

 

相关文章:

  • 2022-12-23
  • 2021-12-28
  • 2022-02-15
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
  • 2022-01-01
  • 2022-01-16
猜你喜欢
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2021-06-17
  • 2021-05-24
  • 2022-12-23
  • 2021-09-20
相关资源
相似解决方案