javascript XHR 请求中的 500 内部服务器错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19265914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
500 Internal Server Error on XHR Request
提问by James Anderson
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?
为什么最后一行会导致 500 Internal Server Error?代码有什么问题还是我需要先记录任何东西才能看到?
回答by Sander_P
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.
最后一行没有任何问题。“500 内部服务器错误”只是服务器作为请求结果发回的结果。
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.
这意味着“/Handlers/newAccount_handler.php”才是真正的问题。如果您在浏览器中打开此 URL,它将显示一个错误。
回答by Joey
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.
这似乎有点旧,但我遇到了类似的问题。值得检查您发送的“#form-step1”的值。在我的例子中,如果值包含引号,它会抛出一个错误,但使用简单的文本它可以正常工作。