I'm in the process of setting up a home automation system using a Raspberry Pi running Raspbian. I plan on creating a web page that will feature checkboxes to control lights through relays. I need help with implementing a checkbox functionality that, when checked, triggers PHP to execute a Python code file for relay control. I've heard that Ajax and JavaScript can be used to post forms without the need to refresh the entire page, but I am not well-versed in these languages. Can someone demonstrate a simple example of a checkbox where checking it runs one PHP exec() command and unchecking it runs another?
Here is an example:
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<title>Raspberry Pi</title>
</head>
<body>
<input type="checkbox" class="iclass" />
<script>
$("input.iclass").click(function (e) {
e.preventDefault();
$.post("post.php", {param1: value, param2: value});
});
</script>
</body>
</html>
The post.php currently only displays alert('Succesful!');
, but there seems to be an issue with its functioning.