0
我已经设置了一个托管在AWS S3上的网站。我的主文件在主目录中设置为index.html,当我打开网站时,它会打开该文件,这正是我想要的。当我去我的网站(mysite.io)时,它被加载到mysite.io,这也是我想要的。我遇到的问题是,如果“/?#”不在URL中,我所执行的回调函数未被执行。网站主页没有执行回调#
从下面的代码可以看出,当用户在登录表单中输入他们的数据时,手机和密码被读入并传递到authenticateUser方法。如果URL中没有“/?#”,则cognitoUser.authenticateUser(...)不会按照以下日志所示执行。
$('#login-form').submit(function() {
var phone = $('#login-phone').val();
var password = $('#login-pass').val();
authenticateUser(phone, password);
});
function authenticateUser(username, password) {
// a bunch of variables created here
console.log("This is always executed");
myVariable.doSomething(someStuff, {
onSuccess: function (result) {
console.log("This is not executed if there is no '?#' after mysite.io/");
},
onFailure: function (err) {
alert("Neither is this");
}
});
console.log("This is also always executed");
}
我在网上找不到任何有关这个错误的东西,真的很感谢一些帮助,因为我对webdev很陌生。
谢谢;工作!所以我希望在每一个表单提交中都有'event.preventDefault()',因为我真的不希望页面在表单提交上重新加载?您希望何时重新加载页面? –
是的,如果你正在使用AJAX,现在应该总是这样,那么使用'event.preventDefault()'。噢,HTML'