我正在尝试学习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
});
}
}
然而,当我单击附加了LogIn功能的按钮时,会发送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
我完全不知所措 - 任何帮助都会受到赞赏。
答案 0 :(得分:0)
好吧,事实证明我的问题出在我用来将controller.logIn绑定到表单提交按钮的Event.observe调用中。通过observe调用调用LogIn会产生AJAX请求,然后重新加载页面 - 这会比网络服务器返回我的请求更快。
这就是请求返回空响应字符串的原因。