【问题标题】:Prototype Ajax.Request never returns原型 Ajax.Request 永远不会返回
【发布时间】:2011-12-28 19:27:03
【问题描述】:

我正在尝试学习 Prototype,所以我拼凑了一个简单的登录页面,其中包含用户名和密码字段以及一个登录按钮。

我有一个控制器类,我想在其中放置我的所有 onclick 函数。

function Controller()
{
    this.logIn = function(){
        this.username = Field.getValue("username");
        this.password = Field.getValue("password");

        this.logInResults = function (response){
            alert(response.responseText);
        }

        new Ajax.Request("../../php/tis/LogIn.php",
            {
                method:'get',
                parameters: {username: this.username, password: this.password},
                onComplete: this.logInResults
            });
    }
}

然而,当我单击附加了登录功能的按钮时,发送了 HTTP 请求,但返回一个空响应字符串。当我手动点击 php 页面的链接时,它就在那里,并且按预期运行。

Firebug 显示如下:

GET http://localhost/AJAXSeedOrder/php/tis/LogIn.php?username=User%20Name&password=
Firebug cannot find _firebugConsole element true Window tis?username=User+Name
Firebug cannot find _firebugConsole element true Window tis?username=User+Name
Firebug cannot find _firebugConsole element true Window tis?username=User+Name

我完全不知所措 - 任何帮助将不胜感激。

【问题讨论】:

    标签: javascript prototypejs


    【解决方案1】:

    好吧,事实证明我的问题出在我用来将 controller.logIn 绑定到表单提交按钮的 Event.observe 调用中。通过观察调用调用 LogIn 将发出 AJAX 请求,然后重新加载页面 - 这会比网络服务器返回我的请求更快。

    这就是请求返回空响应字符串的原因。

    【讨论】:

    • 很高兴你对它进行了排序 - 有几次我遇到了“不可能”的问题,在 SO 上发布了这些问题,发现它们是由我做过/忘记做的一些微不足道的事情引起的。
    • 更尴尬的是,有问题的按钮是 type='submit'...
    • 几天前,我被一个问题难住了,根本原因是我将0 分配给两个不同的常量,我用这两个常量来确定相似的 AJAX 请求之间的差异......跨度>
    猜你喜欢
    • 2019-11-15
    • 2011-07-25
    • 1970-01-01
    • 2012-10-02
    • 2013-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多