Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // AJAX - /js/functions.js at the bottom
- // Update state of checkboxes (RELAY, LED)
- $(function() {
- // for every element state change, code below is executed
- $(document).on("change", ":checkbox", function(){
- // variables holds type and pin, state (0 or 1) and room ID
- name = $(this).attr('name');
- state = (Number(this.checked));
- id_prostor = $(this).attr('title');
- $.ajax({
- type: "POST",
- url: "updateState.php",
- data: { name:name, state:state, id_prostor:id_prostor }
- });
- });
- });
- // PHP - updateState.php
- <?php
- include 'connect.php';
- $name = $_POST['name'];
- $state = $_POST['state'];
- $id_prostor = $_POST['id_prostor'];
- $stmt = "UPDATE items set state = " . $state . "
- where item = '" . $name . "' and id_prostor = " . $id_prostor;
- $res = mysqli_query($dbc, $stmt);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement