Ajax按钮更新数据库值

时间:2015-10-14 16:24:05

标签: php mysql ajax

我开发了一个预订系统,当我点击该按钮时它有一个按钮,它将更新从待定到完成的约会状态。每次我想完成约会,我都要点击几次。我认为只需点击一次即可在ajax中完成。

这是我的代码

if ($_REQUEST['command'] == "send") { // if the command send pressed then 
    mysql_query(" UPDATE bookings SET status='sent' WHERE id=$_REQUEST[id]"); // update bookings and set the Statu of the statuts field to sent

}
if ($_REQUEST['command'] == "Done") { // if the command Done pressed then 
    mysql_query(" UPDATE bookings SET status='Done' WHERE id=$_REQUEST[id]"); //update bookings and set the Statu of the statuts field to Done
}

if ($_REQUEST['command'] == "Delete") {
    mysql_query(" DELETE FROM bookings  WHERE id=$_REQUEST[id]");
}

if($ a [' status'] ==' new'){//如果状态状态等于" new"那么>     echo"确认&#34 ;; //打印出发送动作库存!需要完成!!     } else if($ a [' status'] ==' sent'){     回声"当然? &#34 ;;     // echo"删除&#34 ;;     }

我很感激有人可以帮助我使用ajax类来完成这个功能,

非常感谢提前。

1 个答案:

答案 0 :(得分:0)

您可以使用Jquery Ajax函数,它非常易于实现。示例如下所示

<button onclick="changeStatus('send');"></button>
<button onclick="changeStatus('Done');"></button>
<button onclick="changeStatus('Delete');"></button>
<script type="text/javascript">
function changeStatus(command){
    $.ajax({
            url: "project_url/functoin_name", //where your want to send this request(the php file location)
            type: "POST",
            data: {command: command},
            success: function(response){
                    alert(response);
                }
       });
}


</script>

有关详细信息,请查看此http://api.jquery.com/jquery.ajax/