繁体   English   中英

没有?,网站首页无法执行回调

[英]Website homepage not executing callback without ?#

我已经建立了一个托管在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() 当然,您必须将event Object传递给参数:

$('#login-form').submit(function(ev){
  authenticateUser($('#login-phone').val(), $('#login-pass').val());
  ev.preventDefault();
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM