HTTP 错误 405.0 - 不允许使用 Jquery ajax get 的方法

发布于 2025-01-01 08:39:33 字数 1220 浏览 0 评论 0原文

我正在开发一个表单,用户必须在其中插入用户名。我想检查模糊用户的用户名是否有效:

我添加了此脚本:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

疧_╮線 2025-01-08 08:39:33

首先考虑将您的 JQuery 升级到 1.6.x 版本。

尝试修改脚本的版本:

function checkUsername(){
    var usn = document.getElementsByName('username')[0];
    if(usn.value != "") {
       var html = $.ajax({
       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!";
       }
    }
}

First of all consider upgrading your JQuery to 1.6.x version.

Try this modified version of your script:

function checkUsername(){
    var usn = document.getElementsByName('username')[0];
    if(usn.value != "") {
       var html = $.ajax({
       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!";
       }
    }
}
晨与橙与城 2025-01-08 08:39:33

通常,当我从 Jquery 运行 AJAX 命令时,我的数据属性是一个像这样的数组:

 $.ajax({
    type: "GET",
    url: "checkUsername.php",
    data: {
        usr: usr.value 
    },
   async: false,
   dataType: "text"}).responseText;   

Usually when I run an AJAX command from Jquery, my data attribute is an array like such:

 $.ajax({
    type: "GET",
    url: "checkUsername.php",
    data: {
        usr: usr.value 
    },
   async: false,
   dataType: "text"}).responseText;   
别忘他 2025-01-08 08:39:33

在选项中添加

dataType: 'jsonp',

in the option add

dataType: 'jsonp',
万水千山粽是情ミ 2025-01-08 08:39:33

另一件要做的事情是检查 ajax 调用上方的 javascript 错误,这也会导致 405 错误......

The other thing to do is check for javascript errors above your ajax call, which will also cause the 405 error...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文