【发布时间】:2014-04-03 03:05:50
【问题描述】:
对此的任何帮助将不胜感激。我的脚本似乎可以在 Safari 中运行,但不能在任何其他浏览器上运行?我很茫然,因为我对 Jquery 和解析非常陌生。谢谢!
jQuery(document).ready(function($) {
/* Edit these variables */
var api = "66ffde1312******";
var state = "TX";
var city = "Dallas";
$.ajax({
url : "http://api.wunderground.com/api/" + api + "/conditions/q/" + state + "/" + city + ".json",
dataType : "jsonp",
success : function(parsed_json) {
var icon_url_json = "http://icons.wxug.com/i/c/f/" + parsed_json['current_observation']['icon'] + ".gif";
var icon_json = '<img src ="' + icon_url_json + '" />';
var temp_json = parsed_json['current_observation']['temp_f'];
temp_json += "<span>°F</span>";
var condition_json = parsed_json['current_observation']['weather'];
var real_feel_json = "Feels Like " + parsed_json['current_observation']['feelslike_f'] + "°F";
var wind_json = 'Winds are ' + parsed_json['current_observation']['wind_string'];
var location_json = city + ', ' + state;
document.getElementById("weather-icon").innerHTML = icon_json;
document.getElementById("temp").innerHTML = temp_json;
document.getElementById("condition").innerHTML = condition_json;
document.getElementById("real-feel").innerHTML = real_feel_json;
document.getElementById("wind").innerHTML = wind_json;
document.getElementById("location").innerHTML = location_json;
}
});
});
和html:
<div class = "weather">
<div id = "weather-icon"></div>
<div class = "text-container">
<p id = "condition"></p>
<p id = "temp"></p>
<p id = "real-feel"></p>
<p id="wind"></p>
<p id="location"></p>
</div>
</div>
【问题讨论】:
标签: javascript jquery json cross-browser