<script>
logBox = new Vue({
el: "#logBox",
data: {
email : '',
password: ''
},
methods: {
handelSubmit: function(e) {
data = {};
data['email'] = this.email;
data['password'] = this.password;
$.ajax({
url: 'https://herokuapp.com/api/', //my url
data: data,
type: "POST",
dataType: 'json',
success: function(e) {
if(e.status != false){
alert("Login Success").then(function() {
// Redirect the user
window.location.href = "https://stackoverflow.com/";
console.log('The Ok Button was clicked.');
});
}
else {
alert("failed to login!");
}
}
});
return false;
}
},
});
这是我的登录代码。成功登录后,我需要重定向到成功页面,但window.location.href无效,我无法直接进入新页面。那么,任何人都可以解决我的问题吗?
答案 0 :(得分:0)
alert()
不是承诺。您应该将其修复为:
if (e.status != false) {
alert("Login Success");
// Redirect the user
window.location.href = "https://stackoverflow.com/";
}