pass a string from jQuery to php
In a tiered Autocomplete, I need to pass a string from the first selection into a php script to limit the search in the second tier Autocomplete. After much research, I can't get the string to the php. All files are in the same directory.
Here's the jQuery:
//set countryFilter for the 2nd tier to select stateProvince from only the country selected in the 1st tier
countryFilter="countryAbbrev=" + $('input[name=country]:checked').val(); //eg. countryAbbrev=US
$('stateProvince').autocomplete
({
source: function( request, response )
{
$.ajax(
{
url: "getStateProvince.php",
type: "POST",
data: countryFilter,
dataType: "json", //expect returned data to be in json format
success: function( return_arr )
{
response( $.map( return_arr.getStateProvince, function( item )
{
return{
label: item.name + (item.abbrev ? ", " + item.abbrev : ""),
value: item.abbrev
}
}));
}
});
},
minLength: 2
});
Here's the relevant php - intended to match up countryAbbrev, get the string and print a test. I have also tried using countryFilter and it does not work either.
<?php
$country=$_POST['countryAbbrev'];
print "country is {$country} <br>";
Currently, the php prints country is, but no variable.