SyntaxError:missing)在参数列表天气之后

时间:2015-11-07 16:28:11

标签: javascript

    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并在加载我的自定义脚本之前加载库的天气。脚本看起来像这样

3 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

在第二个位置

缺少最后一行。它应该是})});

答案 2 :(得分:0)

您的代码的最后3行如下

        }
    }
}});

然而,他们应该是

                }
            }
        }); // you missed this );
    });
} // you missed this }