javascript 收到 501 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17431515/
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
Getting a 501 error
提问by Ice
I am getting the following error when I am trying to run this code on the browser. "Error response Error code: 501 Message: Unsupported method ('POST'). Error code explanation: 501 - Server does not support this operation."
当我尝试在浏览器上运行此代码时,出现以下错误。“错误响应错误代码:501 消息:不支持的方法('POST')。错误代码解释:501 - 服务器不支持此操作。”
The following errors were in the browser console:
浏览器控制台中出现以下错误:
"1. Failed to load resource: the server responded with a status of 404 (File not found)
"1. 加载资源失败:服务器响应状态为 404 (File not found)
'http://localhost:8002/js/jquery-1.3.2.min.js'
- Resource interpreted as Script but transferred with MIME type text/plain: pquery-0.0.1.js:1
Failed to load resource http://mdsad.com/p.js?v=1372783767755undefined login.html:61 POST
http://localhost:8002/login.html 501 (Unsupported method ('POST')) login.html:1
Resource interpreted as Script but transferred with MIME type text/plain: pquery-0.0.1.js:1
- GET http://mdsad.com/p.js?v=1372783801500download.js:33"
- 资源被解释为脚本但使用 MIME 类型 text/plain 传输:pquery-0.0.1.js:1
无法加载资源http://mdsad.com/p.js?v=1372783767755undefined login.html:61 POST
http://localhost:8002/login.html 501 (Unsupported method ('POST')) login.html:1
资源被解释为脚本但使用 MIME 类型 text/plain 传输:pquery-0.0.1.js:1
- 获取http://mdsad.com/p.js?v=1372783801500下载.js:33"
The login of users via stackmob also fails. I get a 'Failure' alert message. Here is the code:
用户通过 stackmob 登录也失败。我收到“失败”警报消息。这是代码:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/js/stackmob-js-0.9.1-bundled-min.js"></script>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login Form</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function() {
$(".username").focus(function() {
$(".user-icon").css("left","-48px");
});
$(".username").blur(function() {
$(".user-icon").css("left","0px");
});
$(".password").focus(function() {
$(".pass-icon").css("left","-48px");
});
$(".password").blur(function() {
$(".pass-icon").css("left","0px");
});
});
</script>
<script type="text/javascript">
function nextpage(form){
StackMob.init({
publicKey:"my_key",apiVersion:0
});
var u=document.getElementById('username').value;
var p=document.getElementById('password').value;
var user = new StackMob.User({ username: u, password: p});
user.login(false, {
success: function(model, result, options) {
alert("Success");
StackMob.isUserLoggedIn(form.username.value, {
yes: function() { alert("Yes"); },
no: function() {
alert("No");}
});
},
error: function(model, result, options) {
console.log(result);
alert("Failure");//or print out the error
} }); };
</script>
</head>
<body>
<div id="wrapper">
<div class="user-icon"></div>
<div class="pass-icon"></div>
<form name="login-form" class="login-form" action="" method="post">
<div class="header">
<h1>Login Form</h1>
<span>Fill in the details</span>
</div>
<div class="content">
<input id="username" name="username" type="text" class="input username" value="Username" onfocus="this.value=''" />
<input id="password" name="password" type="password" class="input password" value="Password" onfocus="this.value=''" />
</div>
<div class="footer">
<input type="submit" name="submit" value="Login" class="button" onclick="nextpage(this.form)"/>
<input type="submit" name="submit" value="Register" class="register" />
</div>
</form>
</div>
<div class="gradient"></div>
</body>
</html>
However, I am sure about the stackmob part because it worked well in a simple code of mine. Here is the working simple code:
但是,我确定 stackmob 部分,因为它在我的简单代码中运行良好。这是工作的简单代码:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/js/stackmob-js-0.9.1-bundled-min.js"></script>
<script type="text/javascript">
function nextpage(form){
StackMob.init({publicKey:"my_key",apiVersion:0});
var u=document.getElementById('username').value;
var p=document.getElementById('password').value;
user.login(false, {
success: function(model, result, options) {
alert("Success");
StackMob.isUserLoggedIn(form.username.value, {
yes: function() { alert("Yes"); },
no: function() {
alert("No");
}
});
},
error: function(model, result, options) {
console.log(result);
alert("Failure");//or print out the error
}
});
};
</script>
</head>
<body>
<form>
<table>
<tr><td>Username</td><td><input id="username" type="text"></td></tr>
<tr><td>Password</td><td><input id="password" type="text"></td></tr>
<tr><input type="button" value="LOGIN" onclick="nextpage(this.form)"></tr>
</table>
</form>
</body>
</html>
Can someone please tell me where am I going wrong?
有人可以告诉我我哪里出错了吗?
回答by Fraser
You are running a local server on port 8802 but the javascript file "jquery-1.3.2.min.js" is not at the location specified, hence the 404 error.
您正在端口 8802 上运行本地服务器,但 javascript 文件“jquery-1.3.2.min.js”不在指定位置,因此出现 404 错误。
The 501 error is because the server you are using (presumably something like simpleHTTPServer) doesn't support POST requests.
501 错误是因为您使用的服务器(大概是 simpleHTTPServer 之类的)不支持 POST 请求。
To resolve that error you need to use a server that supports POST requests (e.g. Apache, IIS).
要解决该错误,您需要使用支持 POST 请求的服务器(例如 Apache、IIS)。
回答by lees2bytes
Your importing Jquery twice, and two different versions, this could add all sorts of strange issues assuming the 404 is inaccurate.
您两次导入 Jquery 和两个不同的版本,假设 404 不准确,这可能会添加各种奇怪的问题。
Remove this line:
删除这一行:
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
If nothing else it will clear the 404
如果没有别的,它会清除 404