var __weatherServicesPath; $(function() { __weatherServicesPath = _rootUrl + "WebServices/Weather.asmx/LoadWeather2" }); function loadWeather(container, key, sender) { var params = '{cityName:"' + key + '"}'; $("span.weatherMessage", container.parent()).show(); $.ajax({ type: "POST", cache: false, ifModified: true, contentType: "application/json; charset=utf-8", url: __weatherServicesPath, beforeSend: function(xhr) { xhr.setRequestHeader("Content-type", "application/json; charset=utf-8") }, data: params, dataType: "json", success: function(msg) { msg = eval("(" + msg + ")"); var isValidCity = false; if (msg.dayList) { isValidCity = true; var currentDay = msg.dayList[0]; var widgetTitleElement = $(container).parents(".sort").find("dt>span"); if (widgetTitleElement.attr("defaultTitle") == null) { widgetTitleElement.attr("defaultTitle", widgetTitleElement.text()) } widgetTitleElement.html(widgetTitleElement.attr("defaultTitle") + ":" + msg.city + " " + currentDay.date); container.empty(); var weatherUL = $('<ul class="weatherBox clearfix"><li class="m icon"></li><li class="m"></li></ul>'); var weatherIconContainer = $("li:first", weatherUL); weatherIconContainer.append(String.format('<div id="weatherIconBox_{2}" commandName="weatherIcon" commandArgument="{1}"></div>', _rootUrl, currentDay.icon, 0)); var weatherInfoContainer = $("li:last", weatherUL); weatherInfoContainer.append(String.format('<ul><li><h5>{0}</h5></li><li><span class="h">{1}℃</span>~<span class="l">{2}℃</span></li><li>{3}{4}</li></ul>', currentDay.title, currentDay.h, currentDay.l, currentDay.w, currentDay.winds_b)); container.append(weatherUL); var weatherTipContainer = $('<div class="weatherTip"><label>生活提示：</label><span></span></div>'); $("span:last", weatherTipContainer).html(currentDay.index_ct); container.append(weatherTipContainer); $("div[commandName=weatherIcon]").each(function(index) { var commandArgument = $(this).attr("commandArgument"); var weatherSwf = String.format("{0}flashes/weather/w{1}.swf", _rootUrl, commandArgument); swfobject.embedSWF(weatherSwf, $(this).attr("id"), "65", "65", "9.0.0", _rootUrl + "Scripts/swfobject/expressInstall.swf", {}, { wmode: "transparent" }, { id: $(this).attr("id"), name: $(this).attr("id") }) }) } else { alert("非常抱歉，暂不提供您刚才输入城市的天气信息！") } $("span.weatherMessage", container.parent()).hide(); if (sender) { $(sender).parent().siblings().show(); $(sender).parent().hide(); if (isValidCity == true) { $.cookie($(container).parent().attr("id"), key, { path: "/", expires: 100 }) } } }, error: function(xhr, msg, e) { $(container).append("<span>天气预报数据源暂时不可用…</span>"); $("span.weatherMessage", container.parent()).hide() } }) } if (typeof (Sys) !== "undefined") { Sys.Application.notifyScriptLoaded() };