跨域使用jsonp 获取天气预报

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>注册</title>     
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type ="text/javascript" src="jquery.js"></script>    
</head>
<body>
<script type="text/javascript" src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>   
<div id="content">   
              
          
</div>   
   <script>
$(function(){   
    $.getJSON("http://query.yahooapis.com/v1/public/yql", {   
    q: "select * from json where url='http://m.weather.com.cn/data/101010100.html'",   
    format: "json"   
}, function(data) {   
    var $content = $("#content")   
    if (data.query.results) {  
        var result = JSON.stringify(data.query.results);
        $content.text(result);  
        var obj = eval('('+result+')');
        alert(obj.weatherinfo.city);
    else {   
        $content.text('no such code: ' + code);   
    }   
});   
          
});
</script>
  
</body>
<script>
      
  
  
</script>
</html>
 
 
http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
 
原文地址:https://www.cnblogs.com/jazzka702/p/3340704.html