复选框数据在单击时动态保存到数据库

当我选中复选框时,我需要一些js / ajax / jquery脚本动态地将数据保存到数据库。 当前的复选框或加载到记录旁边的复选框,并根据是否选中它来更改数据库中的变量。但是我选择一个以将其保存到数据库后我必须重新加载页面。 我可以做其他所有事情,但了解如何实现ajax,所以我不必每次提交查询和刷新页面。 任何帮助是极大的赞赏。

<form name="form1aa" method="post" action="process.php?fn=&class=&last= &model=&cas=&upid=&group=1" id="form1a" >  Hardware Software         

Show Extra

用jQuery做,一个简单的例子可能是:

HTML:

    

JS:

 $("input[type='checkbox']").on('click', function(){ var checked = $(this).attr('checked'); if(checked){ var value = $(this).val(); $.post('file.php', { value:value }, function(data){ // data = 0 - means that there was an error // data = 1 - means that everything is ok if(data == 1){ // Do something or do nothing :-) alert('Data was saved in db!'); } }); } }); 

PHP:file.php

  

简单的说…

 $('input:checkbox').click( function() { clicked = $(this).attr('checked'); if (clicked) { /* AJAX the server to tell them it was clicked. */ } else { /* AJAX the server to tell them it was unclicked. */ } } ); 

我可以使这更简单。 首先,你需要一个复选框!

      Check this to Save.   
    
    
  



Start Date Cases Type Damage Comment Cost Payment Status Returned 2 Student Job Status
<input name="paycheck[]" type="checkbox" id="paycheck[]" value=""> <input name="paycheck[]" type="checkbox" id="paycheck[]" value=""> No Data