I am trying for the life of me to try and figure out the jquery ajax thing. I have an HTML dialog that comes up and one has to input some information. When they hit "add" it saves the data (call-add_patient.php) and then what I want is on the original page for the name to come up (the "success") part below.
If there are no people in the list then nothing happens (though it does go into the database so it seems to be an ajax misunderstanding). If there is at least one person in the list then the new person is added.
So, I don't get why this only works if there are people in the list. I tried putting a default empty person person and hoped this would work. It didn't.
The javascript:
$.ajax({
url: 'call-add_patient.php',
type: 'get',
data: {
name: name.val(),
address: address.val(),
city: city.val(),
state: state.val(),
zip: zip.val(),
checked: ids.join(),
CUID: CUID.val(),
losap: losap.val(),
ccnumber: ccnumber.val()
},
dataType: 'json',
cache: false,
success: function(data) {
$("table#users tbody").append("<tr>" + "<td>" + " <a class=\"cjbutton\" style=\"font-size: 6pt;\" href=\"letter/letter.php?UID=" + data.uid + "&losap=" + data.losap + "\">print</a>" + data.name + "</td>" + "</tr>");
},
async: false
});
The PHP that creates the HTML table:
print '<table id="users" class="ui-widget" style="width: 100%;"
style="align: left;"><tbody>';
print '<tr><td> </td></tr>';
while ($row_pt = mysql_fetch_assoc($result_pt)) {
print ' <tr width="100%" align="left"><td align="left">';
print ems_print($row_pt['UID']);
print $row_pt['Patient Name'];
print '</td> </tr>';
}
print '</tbody></table> <br/> ';
The bottom of the call-add_patient.php:
echo json_encode(array('uid' => $id, 'name' => $name ));
I am baffled and really need some help.
Edit: Here is a chunk of code that I thought should work but doesn't. I did not include the call-add_patient.php as I don't believe it is a problem (famous last words). Note, the "alert" provides the proper name so I think that is working. I was reading through Add table row in jQuery and tried to mimic the ideas but it still doesn't seem to be working.
<body>
<?
if( isset( $_REQUEST['submit'] ) )
{
print "here";
?>
<script>
$.ajax({
url: 'call-add_patient.php',
type: 'get',
data:{ name: 'anme'},
dataType: 'json',
success: function(data) {$( "table#users tbody" ).append( "<tr><td>" + data.name + "</td><td></td></tr>" ); alert( data.name ); },
async:false
});
</script>
<?
}
?>
<table id="users">
<tbody>
<tr><td>asdf</td><td>asdf</td></tr>
</tbody>
</table>
<form action="index.php" method="post">
<input type="submit" name="submit">
</form>
</body>