syntax for an if statement inside an ajax data: option
My ajax data option in an Autocomplete works. The whole code section works. Then when I put an if statement into the data: option, I get a Firebug error saying - missing: after property id - and the page fails. I have tried a lot of changes in syntax - with no success. The code section is below. The intent is that when the statement is false, the last line should not execute. Document ready sets country so that the test is true, but I doubt the script executes that far. The jQuery seems to fail on load. When the if statement line is removed, the code works. The if statement selector is the same as the country: selector above it, which works. What change is necessary?
$( "#city" ).autocomplete
({
source: function( request, response )
{
$.ajax(
{
url: "http://ws.geonames.org/searchJSON",
dataType: "jsonp",
data:
{
featureClass: "P",
country: $('input[name=country]:checked').val(),
style: "full",
maxRows: 10,
name_startsWith: request.term,
if($('input[name=country]:checked').val()==="US")
adminCode1: $("#hiddenState").val()
},
. . . other stuff follows