I am trying to send an update query when a checkbox is pressed, using AJAX. How can I do this?
HTML imports:
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script src="js/checkbox.js"></script>
HTML checkbox:
<td>
<input type="checkbox" name="vehicle" value="" class="checkbox"> Ingevoerd<br>
</td>
(Yes my checkbox is in a table, I don't know if this has to be in a form.)
JavaScript code:
$(".checkbox").change(function() {
window.alert(5 + 6);
$.ajax({
url: '../ingevoerd.php'
});
});
(the window.alert is not triggered when I press the checkbox)
PHP code:
$stmt = $db->prepare('UPDATE table SET temp=0 where id = 1');
$stmt->execute();
var_dump('test');
$(".checkbox").click()?.clickinstead of.changeand before do the ajax call verify if the checkbox ischeckedor not