Wednesday, 11 September 2013

jQuery/PHP Post Failure

jQuery/PHP Post Failure

I've got slightly convoluted jQuery and PHP problem here. On my index.php,
a call to a javascript function getCalls() is made.
function getCalls()
{
$('#transportDiv').load('getCalls.php');
}
getCalls.php does a select from SQL database. It returns a table with the
requested data, plus a dynamically generated form for each row, plus a
dynamically generated jQuery post function for each dynamically generated
form (these are being echo()'d, by the way):
<tr>
//Static table data here
</tr>
<form id='form$id' action='update.php' method='post'>
<tr id='tr$id' style='{display: none;}'>
<td class='$tdClass'>
<input type='text' id='txt_municipality' name='municipality'
value='$municipality'>
</td>
//a lot more inputs omitted
</tr>
</form>
<script type="text/javascript">
$("#submitButton'.$id.'").click(
function()
{
$.post( $("#form'.$id.'").attr("action"),
$("#form'.$id.':input").serializeArray(),
function(info)
{
$("#responseDiv").html(info);
}
);
getCalls();
}
);
</script>
$id is a PHP variable containing the unique identifier for each row in SQL
(BTW, those '.$id.' lines are correct, they are within an echo with single
quotes). All of this shows up as expected in my #transportDiv after
getCalls() is invoked, so no problem there. When #submitButton is clicked,
it calls update.php, but there is no post data in the $_POST array:
echo $_POST['municipality'];
That's all I have it doing right now. #responseDiv is populated by the
jQuery post with "Notice: Undefined index: municipality in
C:\inetpub\wwwroot\comm\update.php on line 3". A var_dump() on $_POST
prints "array(0)"
I've been stuck on this for days.. any thoughts?
I've lurked the numerous other posts from other users with similar issues,
but their solutions haven't worked for me.

No comments:

Post a Comment