html获取中国天气,Json获取中国天气网天气预报的代码

本文提供了一段JavaScript代码,该代码用于从中国天气网获取天气预报信息。通过Ajax请求和Json解析,实现动态更新页面上的天气数据,并利用Cookie进行缓存,提高用户体验。

Json获取中国天气网天气预报的代码

文章作者:网友投稿 发布时间:2010-07-14 14:20:08 来源:网络

获取中国天气网天气的代码 var url=escape(http://m.weather.com.cn/data/101210701.html); var cookie_info = cookie_info; var date = new date(); var hours=24-date.gethours()-1; var mins=60-date.getminutes()-1; var secs=60-date.getseconds(); date.settime(date.g

获取中国天气网天气的代码

var url=escape("http://m.weather.com.cn/data/101210701.html");

var cookie_info = "cookie_info";

var date = new date();

var hours=24-date.gethours()-1;

var mins=60-date.getminutes()-1;

var secs=60-date.getseconds();

date.settime(date.gettime() + (1 * hours * 60 * 60 * 1000) + (1 * 1 * mins * 60 * 1000) + (1 * 1 * 1 * secs * 1000));

var rd_cookie_info= $.cookie(cookie_info);

$(function(){

if(rd_cookie_info==null)

{

getdata(url);

}

else{

$("#weather").html(rd_cookie_info);

}

})

function getdata(url)

{

$.ajax({

type:"get",

cache: "false",

url: "ajaxget.asp教程",

data:"url="+url,

datatype: "html",

error: function(){$("#weather").html("读取失败...请刷新重试!");},

success: function(网页特效on){

var t = '('+json+')';

var result = eval(t);

var getinfo="";

getinfo+=result.weatherinfo.date_y+" ";//年月日

getinfo+=result.weatherinfo.date+" ";//农历年月日

getinfo+=result.weatherinfo.week+" ";//星期几

getinfo+="

";//换行 veryhuo.com

getinfo+=result.weatherinfo.city;//获取城市名称

getinfo+="

c "//天气图片1

getinfo+="

c ";//天气图片2

getinfo+=result.weatherinfo.weather1+" ";//天气情况

getinfo+=result.weatherinfo.temp1;//温度

$.cookie(cookie_info,getinfo, { path: '/', expires: date });

$("#weather").html(getinfo);

}

});

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值