我检索到的数据从MySQL表到HTML页面即
i retrieved data from mysql table into html page i.e
$query="select * from student";
$result=mysql_query($query)or die(mysql_error());
while($rs=mysql_fetch_array($result))
{
?>
<tr>
<td align="center"><?php echo $rs['st_id']; ?></td>
<td align="center"><?php echo $rs['name']"; ?></td>
<td align="center"><input type="checkbox" name="checked[]" <?php if($rs['checked']==1){echo "checked"; } ?> /></td>
<td align="center"><a href="delete_student.php?id="><img src="images/delete_icon.png" alt="Delete" /></a></td>
<td align="center"><a href="update_student.php?id="><img src="images/update.png" alt="Update" /></a></td>
这是给我的输出
this is gives me the output
假设ID 1的复选框被选中,并从MySQL表中检索。 现在我想做的事情是,当我检查了remaing 2复选框到此表和函数调用阿贾克斯都到PHP页面,并根据给定的ID更新检查字段的值(即2在这种情况下,3)。不刷新整个页面,也没有更新整个记录的复选框只是价值。我是新来的阿贾克斯这样 任何帮助将大大AP preciated。
assume that checkbox of id 1 is checked and retrieved from mysql table. Now what i want to do is that when i checked the remaing two checkbox into this table and a function is called to ajax which goes to php page and update the value of checked field according to the given id (i.e 2 and 3 in this case). Not refreshing the whole page nor updating the whole record just the value of check box. i am new to ajax so any help would be greatly appreciated.
推荐答案
是的,探索jqGrid的是不浪费时间的。但是,因为要更新只在复选框值的变化。这里是你可以做什么。
Yes, exploring jqGrid isn't a waste of time at all. However, since you want to update only on change of checkbox value. Here's what you can do..
<input type="checkbox" name="check1" />
和..
$().ready(function(){
var st_id = <?php echo $rs['st_id']; ?>;
//Or you could use a hidden field in the form
$(':checkbox').click(function(){
var chkName = $(this).attr('name');
var checkVal = $(':checkbox[name='+chkName+']').attr('checked');//true or false
$.ajax({
url: 'MyApp/update.php?checboxName=' + checkVal,//Do update on server-side
success: function(data) {
alert('Updated successful.');
}
});
});
});
另外,你可以做一个 $('formID')。序列化()
wihch返回name = value对了就可以在调用附加的所有表单元素你的PHP脚本。
Also, you can do a $('formID').serialize()
wihch returns name=value pairs of all form elements that can then be appended in the call to your php script.
相关推荐
最新文章