日期:2014-05-16 浏览次数:20451 次
$(function(){
$.ajax({
type:"post",
url:"http://m.weather.com.cn/data/101010100.html", //中央台天气预报
dataType:"json",
success:function(data){
var test = eval(data);
alert(1); //这个都没有反应啊T_T
alert(test.weatherinfo.city);
}
});
})
<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>