Php 如何使用切换按钮用Ajax更新数据库?
嗨,如果我按下按钮,我希望滑块硬度为1。我该怎么做 我的按钮: 代码:slider.phpPhp 如何使用切换按钮用Ajax更新数据库?,php,html,jquery,ajax,Php,Html,Jquery,Ajax,嗨,如果我按下按钮,我希望滑块硬度为1。我该怎么做 我的按钮: 代码:slider.php <td> <div class="custom-control custom-switch custom-switch-success custom-switch-glow custom-control-inline"> <input type="checkbox" class="custom-con
<td>
<div class="custom-control custom-switch custom-switch-success custom-switch-glow custom-control-inline">
<input type="checkbox" class="custom-control-input" id='<?php echo $row['slider_id']; ?>' <?php echo $row['slider_durum']==1?'checked':'' ?>>
<label class="custom-control-label" for="<?php echo $row['slider_id']; ?>"></label>
</div>
</td>
<script>
$(document).ready(function () {
$('.custom-control-input').click(function (event) {
var slider_id = $(this).attr("slider_id"); //take id value
var slider_durum = ($(this).is(':checked')) ? '1' : '0';
//We receive active or passive information according to the checkbox.
$.ajax({
type: 'POST',
url: 'islem.php', //my process page
data: { slider_id:slider_id, slider_durum: slider_durum }, //post data
error: function () {
alert('Hata');
}
});
});
});
</script>
>
欢迎来到SO。您需要更具体地说明需要完成什么,以及在显示的代码中遇到的问题。还要告诉我们什么是有效的,什么是无效的,以及遇到的所有错误。好的代码缩进将帮助我们阅读代码,更重要的是,它将帮助您为自己的利益调试代码。您可能会被要求在几周/几个月内修改此代码,最终您将感谢我。