I’m trying to send POST requests to a PHP file through JQuery’s AJAX. Passing the data part of the request causes it to fail, returning a 400 error, but removing the data part causes it to succeed… kind of. I have this AJAX request in JavaScript:
$.ajax({
url: "connect.php",
type: "post",
data: {
"action": "addMessage",
"username": username,
"message": imgData
},
dataType: 'text',
success: function(data, status, xhr) {
console.log("Success!");
},
error: function(jqXHR, textStatus, errorThrown) {
console.error(textStatus, errorThrown);
}
});
And all that’s in connect.php is “<?php echo "test"; ?>”. So it should display “test” right? Instead, with the data parameter, it gives a 400 error and without it, it “succeeds” but doesn’t display “test”. Any reason why AJAX doesn’t work? I know it worked a few months ago while working on another project.
Side note: running the exact same thing on a local web server with PHP works as expected, it’s just on 000webhost that it doesn’t work.