Ember js:在我的例子中,为什么路由器中的逻辑会继续,即使其中使用的功能还没有完成
Ember js: In my example why does the logic in the router continue even though the function used in it has not completed?
我是ember js的新手,我正在努力理解路由:)
这是我的控制器代码:
App.AppController = Em.ArrayController.extend({
login: App.Login.create({}),
loginUser: function(){
$.ajax({
type: 'POST',
cache: false,
url: contextPath + 'user/register',
data:{name:this.login.name, email:this.login.email,password:this.login.password,confirmPassword:this.login.confirmPassword,acceptTerms:this.login.acceptTerms},
success: function(data) {
alert('success!');
},
error: function(jqXHR, textStatus, errorThrown) {
}
});
}
})
下面是我使用这个函数的地方:
App.ChooseServiceIndexRoute = Em.Route.extend({
redirect: function() {
var isLoggedIn = this.controllerFor('app').loginUser();
alert(isLoggedIn);
if(isLoggedIn){
this.transitionTo('chooseService');
}
else {
this.transitionTo('app');
}
}
});
看起来,函数loginUser被调用了,但是alert(isLoggedIn)在函数完成之前发生了(alert(success)在alert(isLoggedIn)之后发生。
我需要一些帮助来理解发生了什么事。
谢谢!
Ajax意味着异步Javascript和XML,所以根据定义它是异步的,这意味着它在完成之前不会停止代码,而是在完成加载后运行回调。您可以将async设置为false,以便在完成之前停止执行。不过,您必须小心超时和类似的情况。
查看这里可用的选项:$。ajax文档
相关文章:
- 如何让JS脚本在导航后继续运行(谷歌chrome控制台)
- Video.js没有'暂停后无法继续
- 隐藏 Raphael JS Freetransform 上的手柄,但继续拖动
- 如何在Node.js中等待函数完成后再继续
- d3.js继续条件加载数据
- 正在处理.js - 当鼠标离开画布时继续交互
- 即使在 JS 中声明后,继续的时间也已过
- 鲍尔JS文件在咕噜咕噜遵守后继续丢失
- 使用节点时是否有等效的语句“继续”.js 为每个系列异步
- 使用sketch.js继续编辑草图图像
- 使用fabric js克隆画布并继续编辑
- 如何在repl/bash w/Node.js Commander中继续接收异步console.log消息
- 如何用一个元素上的onclick中断IntroJS.js教程,然后继续
- Raphael JS -鼠标悬停时开始/继续动画.鼠标离开时暂停动画
- popcorn.js可以检测切换视频,无需重启即可继续
- 使页面在执行JS后继续前进
- JS继续加载,直到img src改变
- 基于弹出式继续执行JS函数
- 继续在我的node.js服务器上获得以下警告
- js继续和中断循环