i am getting this error (index):31 POST https://amrit.github.io/scripts/sendData.php net::ERR_FAILED 405
function ajaxpost() {
// (A) GET FORM DATA
var form = document.getElementById("myForm");
var data = new FormData(form);
// (B) AJAX
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://amrit.github.io/scripts/sendData.php");
//
//xhr.open("POST", "scripts/sendData.php");
// What to do when server responds
xhr.onload = function() {
console.log(this.response);
};
xhr.send(data);
}
i am getting following error when i deploy the html on website. Uncaught SyntaxError: Unexpected token '<', "<?php "... is not valid JSON at JSON.parse () at xmlhttp.onreadystatechange
function get_component_states() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "scripts/receiveData.php", true);
xmlhttp.send();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// update the form with the new values
// stringify the response
var response = JSON.parse(this.response);
//var response = JSON.parse(this.response);
console.log(response);
// update the form with the new values
document.getElementsByName("mainVoltage")[0].innerHTML = response.mainVoltage;
document.getElementsByName("loadPower")[0].innerHTML = response.loadPower;
document.getElementsByName("exportPower")[0].innerHTML = response.exportPower;
document.getElementsByName("solarPower")[0].innerHTML = response.solarPower;
document.getElementsByName("todayKwh")[0].innerHTML = response.todayKwh;
document.getElementsByName("totalKwh")[0].innerHTML = response.totalKwh;
document.getElementsByName("circuit1")[0].checked = response.circuit1;
}
// show the response in the console
console.log(this.response);
};
}