2014-03-02 183 views
0

任何幫助與此將不勝感激。我的腳本似乎在Safari中工作,但不適用於任何其他瀏覽器?我很茫然,因爲我是Jquery和解析的新手。謝謝!我的腳本不適用於Chrome和Firefox(Mac),但適用於Safari?

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> 

回答

0

最好的辦法是在Chrome中進行調試,並找出在哪些確切的行被打破。在Chrome上,您可以按F12在控制檯中查看錯誤。在此之前,可能會嘗試評論天氣圖標div設置內部html,這對我來說似乎有點奇怪。

相關問題