I have been getting this error for quite a while and it's driving me crazy. I would like to send a POST request to a PHP file with ajax using XMLHTTPRequest(). This is the error that I get: Edge console
Here is my Javascript code:
function sendAndReceive(string, user) {
let http = new XMLHttpRequest();
let url = "http://127.0.0.1:5500/forum/js/forum.php";
let message = "message=" + string;
let username = "&user=" + user;
let sendString = message + username;
http.open("POST", url, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("testAJAX").innerHTML = this.responseText;
}
};
console.log(sendString);
http.send(sendString);
document.getElementById("testAJAX").innerHTML = "Loading...";
}
I'm fairly new to Javascript so the error might be trivial. I also use the Visual Studio Code Live Server to bypass the CORS policy type errors, it might have to do with this. Also I've seen a lot of answers pointing you towards jQuery, however this is for a school project and I can't use it.
Thank You to anyone that answers.