EDIT: This is solved. Thank's to everyone who pointed me towards the error log files. Amazing community, this got answered so much faster than I expected. I'm embarred to say... it was a semicolon.
As a study project, I'm working on a home automation based on a Raspberry Pi.
I installed Apache and built a small website that functions as a GUI. On click, data will be sent via POST-request to ajax.php
(in the root folder) which then writes stuff into text files (that then will be read by a python script to do things with the GPIOs - not very elegant, but that's the task now).
Some relevant code:
$("#R0Light1_on").click(function(){
var Value = $(this).val();
var data = {'id': 'R0Light1_on', 'value': Value};
$.ajax({
type: 'POST',
url: 'ajax.php',
data: data,
success: function(){
console.log("#R0Light1_on", data);
$("#R0Light1_on").addClass("on");
$("#R0Light1_off").removeClass("off");
},
error: function() {alert('ERROR: $.ajax #R0Light1_on');}
});
});
<?php
if (isset($_POST['id'])) {
switch ($_POST['id']){
case 'R0Light1_on':
R0Light1_on();
break;
case 'R0Light1_off':
R0Light1_off();
break;
}
}
function R0Light1_on() {
$content = "Not relevant to this Question";
$fp = fopen("/var/www/html/shares/pi/R0Light1_on.txt","wb");
fwrite($fp,$content);
fclose($fp);
exit;
}
function R0Light1_off() {
...
}
?>
<button type="button" id="R0Light1_on" value="1">an</button>
AJAX worked for a month now. 200 ok
, all the time and $_POST['id']
did it's job. Then yesterday, it stopped doing so. I don't know what I did, but now it's throwing 500 Internal Server Error
messages at me. Even using back-up files doesn't help me and I feel like I read everything Google could find me.
One Thing do I know, though: when I remove the if(isset($_POST['id']))
-part, the HTTP-request is successful again (it just also make's the php-script useless, as obvious).
Btw, changing everything to GET
doesn't help either (data is visible in URL, but the error stays the same).
Thanks for your time, I'd really appreciate any kind of help.