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'