浏览器尝试打开Javascript代码作为文件结构

时间:2017-03-20 23:07:08

标签: javascript jquery html google-maps

我尝试加载网站时遇到错误。每当我在浏览器中打开index.html时,我都会得到problem loading page响应。响应很混乱,因为通常我希望这表明文件无法加载,但我的响应显示如下:

Firefox can’t find the file at /home/crow/UdacityProjects/mapapp/function (data) { // Setting Self var self = this; this.name = data.name; this.lat = data.lat; this.long = data.long; this.URL = ""; this.street = ""; this.city = ""; this.phone = ""; this.visible = ko.observable(true); // Foursquare URL var foursquareURL = 'https://api.foursquare.com/v2/venues/search?ll=' this.lat ',' this.long '&client_id=' clientID '&client_secret='

它继续,但我已经把剩下的空间留了下来。正如您可以看到它尝试在URL中加载我的代码,为什么会发生这种情况呢?

我已将浏览器似乎试图加载文件的javascript代码包含在内:

// --- Location information and foursquare URLJSON.
var location = function(data) {

  // Setting Self
  var self = this;
  this.name = data.name;
  this.lat = data.lat;
  this.long = data.long;
  this.URL = "";
  this.street = "";
  this.city = "";
  this.phone = "";
  this.visible = ko.observable(true);

这是我的index.html文件:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Bolton Hill Neighborhood Map</title>
  <link rel="stylesheet" href="static/main.css">
  <meta name="viewport" content"width=device-width, initial-scale=1">
</head>
<body>
 <div class='map'>maps error</div>

  <script src="/js/knockout.js"></script>
  <script src="/js/jquery.min.js"></script>
  <script src="/js/app.js"></script>
  <script async defer src="https://maps.googleapis.com/maps/api/js?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&callback=initApp&libraries=places" onerror="errorHandler"></script>
</body>
</html>

我的目录结构如下:

myapp
|
  CSS
   |
    main.css
  JS
   |
    knockout.js
    core.js
    jquery.min.js
    app.js

  index.html

我不确定我在这里做错了什么,如果有人能给我一些建议,我真的很感激。谢谢!

1 个答案:

答案 0 :(得分:2)

location是一个Javascript keyword。重命名变量。