I've got a table of which I'm trying to add inline-edit to, but I'm really new to ajax. I suspect there's something wrong with the dataString
of my Ajax code but I can't find it. The code itself works, but I'm having trouble with posting the data.
I'm sorry if this kind of question has been asked before, I'm really stressing about this. If anybody can tell me what to do, I'd appreciate it a lot.
Database
rowid | Person
4 | mike
12 | peterson
PHP
//Every row in the sql table has an row id
<php $id = $row['rowid']; ?>
<tr id="<?php echo $id ?>" class="tredit>
<td>
<span id="person_<?php echo $id ?>" class="text"><?php echo $row["Person"] ?></span>
<input type="text" class="ip" id="person_ip_<?php echo $id ?>" value="<?php echo $row["Person"] ?>">
</td>
</tr>
Ajax
$(document).ready(function(){
$(".tredit").click(function(){
var ID=$(this).attr('id');
$("#person_"+ID).hide();
$("#person_ip_"+ID).show();
}).change(function(){
var ID=$(this).attr('id');
var first=$("#person_ip_"+ID).val();
var dataString = 'id='+ ID +'&person='+first;
//alert(dataString);
$("#person_"+ID).html('<img src="load.gif" />');
if(first.length > 0){
$.ajax({
type: "POST",
url: "post_table.php",
data: dataString,
cache: false,
success: function(html){
$("#klant_"+ID).html(first);
}
});
}else{
alert('Voer iets in');
}
});
});
post_table.php
<?php
$person= $_POST['person'];
$id = $_POST['id'];
//This is where I get stuck, I don't know how to extract data from the dataString to insert into an update
$query = "update people set Person='$person' where id='$id'";
mysql_query($query, $con);
?>