Here is my code:
var fd = new FormData(document.querySelector('#form-step1')); var xhr = new XMLHttpRequest(); xhr.open('POST', '/Handlers/newAccount_handler.php', true); xhr.send(fd); // this line is causing a 500 Internal Server Error and the data is not saved to the MySQL table
Why is the last line causing a 500 Internal Server Error? Is there anything wrong with the code or do I need to log anything first to see?Answer1:
There is nothing wrong with the last line. The '500 Internal Server Error' is simply the result the server sends back as the result of the request.
This means that '/Handlers/newAccount_handler.php' is the real problem. If you open this URL in a browser it will show you an error.Answer2:
This seems a bit old, but I've had similar issue. It's worth checking what the value of '#form-step1' you are sending. In my case if the value contained quotes it would throw an error, but with simple text it worked fine.