我正在尝试学习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我完全不知所措--任何帮助都将不胜感激。
发布于 2010-08-14 12:11:23
事实证明,我的问题出在用于将controller.logIn绑定到表单提交按钮的Event.observe调用中。通过observe调用调用LogIn将发出AJAX请求,然后重新加载页面-这将比then服务器返回我的请求更快。
这就是为什么请求会返回空响应字符串的原因。
https://stackoverflow.com/questions/3481110
复制相似问题