迷路的0161

博客园 首页 联系 订阅 管理

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="jquery.js"></script>
<script type="text/javascript">
function getIntface(){
//?cityname=北京&key=e4bc21879a649b8db8ed5a6ed81e3610&dtype=json
$.ajax({
type : "get",
async:false,
url:"http://op.juhe.cn/onebox/weather/query",
data:{"cityname":"北京","key":"e4bc21879a649b8db8ed5a6ed81e3610","dtype":"json"},
dataType : "jsonp",
jsonp: "jsoncallback",
jsonpCallback:"success_jsonpCallback",
success : function(json){
alert(json);
}
});
}
function getIntface2(){
var url = "http://op.juhe.cn/onebox/weather/query";
var data = {"cityname":"北京","key":"e4bc21879a649b8db8ed5a6ed81e3610","dtype":"json"};
$.ajax({
type : "get",
async : false, //同步请求
url : url,
data : data,
dataType : "jsonp", //跨域请求需要使用jsonp
contentType: "application/x-www-form-urlencoded; charset=utf-8",
timeout:1000,
success:function(json){
alert(json.reason); //请求成功前台给出提示
alert(json.result.data.realtime.city_code);
},
error: function() {
alert("失败!");
}
});
}
</script>
</head>
<body>
<input type="submit" value='load' onclick="getIntface()">
<input type="submit" value='load' onclick="getIntface2()">


</body>
</html>

posted on 2016-11-02 13:15  迷路的0161  阅读(157)  评论(0编辑  收藏  举报