views:

37

answers:

2

Hello,

For the life of me, I can't seem to find the issue with my javascript. Firebug is spitting out the following error:

missing ) after argument list
[Break on this error] $.getJSON('http://local.yahooapis.co... results +'&output=json&callback=?',\n

Here is my code:

function getLocationJSON(fooBar) {

 var appid = 'RvkxtGN.OtlDnsdkjsdP_DsOD3xXzFlW6LL6u3y3wTcW4zWZVgQL9O14X78ZoBY9c-';
 var results = 5;
 var query = 'pizza';
 var lat;
 var lon;

 $('#whereLocationSelector').click(function() {

function setDisplay(text) {
  $('#whereLocationSelector').empty().append(text);
}

jQT.updateLocation(function(coords){
  if (coords) {
    setDisplay('Location Acquired!');
    lat = coords.latitude;
    lon = coords.longitude;
  } else {
    setDisplay('Device not capable of geo-location.');
  }
});

}

$.getJSON('http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=' + appid   + '&query=' + query + '&latitude=' + lat +'&longitude=' + lon + '&results=' + results + '&output=json&callback=?',
function(funWorld) {
  console.log(funWorld);
});  
}

Any suggestions on best practices to debug this on my own in the future would be greatly appreciated.

+1  A: 

You should place your functions outside. For

$('#whereLocationSelector').click(function() {

the closing tag was incorrect. I have fixed that below:

function getLocationJSON(fooBar) {

 var appid = 'RvkxtGN.OtlDnsdkjsdP_DsOD3xXzFlW6LL6u3y3wTcW4zWZVgQL9O14X78ZoBY9c-';
 var results = 5;
 var query = 'pizza';
 var lat;
 var lon;

 $('#whereLocationSelector').click(function() {

function setDisplay(text) {
  $('#whereLocationSelector').empty().append(text);
}

jQT.updateLocation(function(coords){
  if (coords) {
    setDisplay('Location Acquired!');
    lat = coords.latitude;
    lon = coords.longitude;
  } else {
    setDisplay('Device not capable of geo-location.');
  }
});

});

$.getJSON('http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=' + appid   + '&query=' + query + '&latitude=' + lat +'&longitude=' + lon + '&results=' + results + '&output=json&callback=?',
function(funWorld) {
  console.log(funWorld);
});  
}
Alec Smart
+2  A: 

You need to } with }); before

$.getJSON('http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=' + appid   + '&query=' + query + '&latitude=' + lat +'&longitude=' + lon + '&results=' + results + '&output=json&callback=?', line

That is, replace

}

$.getJSON('http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=' + appid   + '&query=' + query + '&latitude=' + lat +'&longitude=' + lon + '&results=' + results + '&output=json&callback=?',
function(funWorld) {
  console.log(funWorld);
});  
}

With

});

$.getJSON('http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=' + appid   + '&query=' + query + '&latitude=' + lat +'&longitude=' + lon + '&results=' + results + '&output=json&callback=?',
function(funWorld) {
  console.log(funWorld);
});  
}
Yogesh