2015-11-07 46 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 } 
相关问题