-1

My chrome console gives this error:

  Uncaught SyntaxError: Unexpected token } server.js:11

Here's the code:

$(function(){
var servers = "http://site-with-json.com/example"

  $.getJSON(servers, function (serverData) {
      $.each(serverData.serverList, function() {
          $.each(this, function(k, v) {
              if (k == "serverName") 
                  {
                    $( "#browser" ).append( '<div class="server">'+v'</div>' )
                    }
              });
        });
    });
});

Where the json looks like this:

{
  "serverList": [
    {
      "serverName": "Server 1",
      "online": true
    },
    {
      "serverName": "Server 2",
      "online": false
    }
  ]
}

Any idea what the error could be? Thanks.

4

2 回答 2

6

+您在以下行中缺少srvname

$( "#browser" ).append( '<div class="server">'+srvname+'</div>' );

同样正如@smerny 指出的那样,您必须将 srvname 替换v为,因为没有调用变量srvname

于 2013-09-05T13:47:06.667 回答
4

检查这一行

 $( "#browser" ).append( '<div class="server">'+srvname'</div>' )

它应该是:

 $( "#browser" ).append( '<div class="server">'+srvname+'</div>' )

另外,我没有srvname在您的代码中看到声明

于 2013-09-05T13:48:40.003 回答