HTTP 错误 405.0 - 不允许使用 Jquery ajax get 的方法
我正在开发一个表单,用户必须在其中插入用户名。我想检查模糊用户的用户名是否有效:
我添加了此脚本:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
IN HTML:
<input name="username" type="text" onblur="checkUsername()">
脚本:
function checkUsername(){
var usn = document.getElementsByName('username')[0];
if(usn.value != "") {
var html = $.ajax({
type: "GET",
url: "checkUsername.php?",
data: "usr=" +usr.value
async: false,
dataType: "text"}).responseText;
if(html == "si") {
usn.style.backgroundColor = "green";
} else {
usn.style.backgroundColor = "red";
usn.value = "Username still exists!";
}
}
}
所以 onBlur
不起作用,当我提交表单时,会出现如下错误:
HTTP Error 405.0 - Method Not Allowed
The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.
什么我可以做什么吗?问题出在哪里?
I'm developing a form in which user must insert an username. I want to check on blur that username of user is valid:
I added this script:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
IN HTML:
<input name="username" type="text" onblur="checkUsername()">
Script:
function checkUsername(){
var usn = document.getElementsByName('username')[0];
if(usn.value != "") {
var html = $.ajax({
type: "GET",
url: "checkUsername.php?",
data: "usr=" +usr.value
async: false,
dataType: "text"}).responseText;
if(html == "si") {
usn.style.backgroundColor = "green";
} else {
usn.style.backgroundColor = "red";
usn.value = "Username still exists!";
}
}
}
So onBlur
doesn't work, and when I submit form it appear an error like this:
HTTP Error 405.0 - Method Not Allowed
The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.
What can I do? Where is the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先考虑将您的 JQuery 升级到 1.6.x 版本。
尝试修改脚本的版本:
First of all consider upgrading your JQuery to 1.6.x version.
Try this modified version of your script:
通常,当我从 Jquery 运行 AJAX 命令时,我的数据属性是一个像这样的数组:
Usually when I run an AJAX command from Jquery, my data attribute is an array like such:
在选项中添加
in the option add
另一件要做的事情是检查 ajax 调用上方的 javascript 错误,这也会导致 405 错误......
The other thing to do is check for javascript errors above your ajax call, which will also cause the 405 error...