500 Internal Server Error on XHR Request

僤鯓⒐⒋嵵緔 提交于 2019-12-13 04:23:02

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/19265914/500-internal-server-error-on-xhr-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!