Mazey Mazey - 18 days ago 5
Javascript Question

Javascript/Jquery unexpected }

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.

Answer

You have a missing + in the following line after srvname

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

Also as @smerny pointed out you have to replace srvname with v as there is no variable called srvname