jQuery with PHP - dead as a dodo
I have a (client) PHP page which makes a jQuery call to a server PHP page. The elements of the jQuery code designed to work on the client page are working fine (select enable/disable) but I am getting no response from the server PHP page whatsoever.
On the client page I have a couple of menu selects, the second (selectAdminGroup) being populated as a result of the selection on the first (selectDocZone)...
-
<form action="testClient.php" method="get" name="form1">
<table>
<tr>
<td>
<select id="selectDocZone" class="docZone">
<option value="0">Select a document zone...</option>
<?php
for ($i = 2; $i < 11; $i++)
{ ?>
<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
<?php } ?>
</select>
</td>
<td>
<select id="selectAdminGroup" class="adminGroup" disabled="disabled">
<option value="0">Select an admin group...</option>
</select>
</td>
</tr>
</table>
</form>
and the jQuery calling function in the head of the client to populate the second select is...
-
$(document).ready(function()
{
$('#selectDocZone').change(selectZoneVal);
function selectZoneVal()
{
var zoneSelected = $('#selectDocZone option:selected').val();
// Always return selectAdminGroup back to zero option on change of zone
$('#selectAdminGroup option:nth(0)').attr('selected','selected');
if (zoneSelected != 0)
{
$('#selectAdminGroup').removeAttr('disabled');
$.getJSON('testServer.php', {id: zoneSelected}, function(data)
{
$('#selectAdminGroup').empty();
$.each(data, function()
{
var option = $('<option/>').attr('value',this.agPK).text(this.agM);
$('#selectAdminGroup').append(option);
});
});
}
else
{
$('#selectAdminGroup').attr('disabled', 'disabled');
}
}
});
To test the server page there is code to produce junk
-
$ret = array();
for ($i = 0; $i < 10; $i++)
{
$ret[] = array(agPK=>$i, agM=>$i);
}
echo json_encode($ret);
exit;
To reiterate, the enable/disable is working but I get no response at all from the server file. Once it reaches $.getJSON everything stops. I have tested the jQuery routine by putting an alert in just before the call to the server page and that fires. The jQuery has also been tested by creating an html client file using the manual select code below and that works fine. There seems to be some kind of problem with putting the jQuery into the client PHP file but I can't see what it is. All help gratefully received!
-
<select id="selectDocZone">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<select id="selectAdminGroup"></select>