2015-11-07 51 views
-1
var x = document.getElementById("demo"); 


    if (navigator.geolocation) { 
     navigator.geolocation.getCurrentPosition(showPosition); 
    } else { 
     x.innerHTML = "Geolocation is not supported by this browser."; 
    } 

function showPosition(position) { 

    var location = position.coords.latitude + 
    "," + position.coords.longitude;  


jQuery(document).ready(function($) { 

    $.ajax({ 
    url : "https://api.wunderground.com/api/0ce1c4a981f7dd2a/geolookup/conditions/q/"+location+".json", 
    dataType : "jsonp", 

    success : function(parsed_json) { 
    var location = parsed_json['location']['city']; 
    var temp_f = parsed_json['current_observation']['temp_f']; 
    x.innerHTML = "Current temperature in " + location + " is: " + temp_f; 

    var forecast = parsed_json['forecast']['txt_forecast']['forecastday']; 
for (index in forecast) { 
var newForecastString = '' + forecast[index]['title'] + ' سيكون ' + forecast[index]['fcttext_metric']; 
var newForecastParagraph = $('<p/>').text(newForecastString); 
      $(".astro").append(newForecastParagraph); 
     } 
    } 
}}); 

我試圖做一個天氣,首先檢查頁面上的jQuery,並在加載我的自定義腳本之前加載庫,如果有必要。該腳本看起來像這樣SyntaxError:missing)在參數列表weather後

+3

什麼是你的問題/問題? –

+0

大多數遊戲機都會指出錯誤出現在哪一行......您發佈的代碼不完整......相當少和}缺少 –

+2

正確格式化您的代碼並且很容易發現。 – epascarello

回答

1

這是更正的一個。 你可以在這裏測試你的JavaScript:http://www.javascriptlint.com/online_lint.php

var x = document.getElementById("demo"); 

if (navigator.geolocation) { 
navigator.geolocation.getCurrentPosition(showPosition); 
} else { 
x.innerHTML = "Geolocation is not supported by this browser."; 
} 

function showPosition(position) { 
    var location = position.coords.latitude + "," + position.coords.longitude;  
    jQuery(document).ready(function($) { 

    $.ajax({ 
     url : "https://api.wunderground.com/api/0ce1c4a981f7dd2a/geolookup/conditions/q/"+location+".json", 
     dataType : "jsonp", 

     success : function(parsed_json) { 
     var location = parsed_json['location']['city']; 
     var temp_f = parsed_json['current_observation']['temp_f']; 
     x.innerHTML = "Current temperature in " + location + " is: " + temp_f; 

     var forecast = parsed_json['forecast']['txt_forecast']['forecastday']; 
     for (index in forecast) { 
      var newForecastString = '' + forecast[index]['title'] + ' &#1587;&#1610;&#1603;&#1608;&#1606; ' + forecast[index]['fcttext_metric']; 
      var newForecastParagraph = $('<p/>').text(newForecastString); 
      $(".astro").append(newForecastParagraph); 
     } 
     } 
    }); 
    });//add this code. Need to close the 'jQuery(document)' 
} // added this code. Need to close the function showPosition 
+0

說明什麼是錯的 – epascarello

+1

我剛剛更新了代碼塊,您錯過了關閉某些功能 –

+0

您的解釋不太符合標誌 - 您說你加了});和} ...但你實際上添加了一個);在最後兩個}}之間,然後在最後一個之後添加一個}); –

0

最後一行丟失),排在第二位。它應該是 })});

+0

非常想 – aligassan

0

最後3行代碼是

 } 
    } 
}}); 

但是如下,他們應該是

   } 
      } 
     }); // you missed this); 
    }); 
} // you missed this } 
相關問題