我是ember的新手。我设计了一个ember应用程序并将fb登录集成在其中,并且必须将facebook accessstoken发送到app后端(post request)并获取后端(rails)生成的令牌。
我的帖子请求回复是:
{
"token":"71fcb8c39dc6449e2ac8e88d21e4d008cf746e16a774aa8755f6be0dbc43849265f9010111986a912fde60de4f76eb5a600ec286b26ea0a865cc7f5cab49330a",
"user":{"role":"unverified"}
}
,组件
import Ember from 'ember';
export default Ember.Component.extend({
fb: Ember.inject.service(),
session: Ember.inject.service(),
authenticate: function(accessToken) {
console.log("accesstoken: "+accessToken);
Ember.$.ajax({
url: "http://localhost:3000/v1/sessions/fb_login",
accepts: 'application/json',
data: { token: accessToken},
crossDomain: true,
headers: {
'Client-Key': '403cb982d0c48473bee32b41b6765e15a26c595c689c620cece5fc15370c33c9c9f6d071f84bf6b88baf466f653f44b4524634bde6fbe68f065f06268f7ed7e2',
},
type: 'post',
success:function(data){
console.log('data is '+data);
}
});
},
actions: {
fb_login() {
this.get('fb').login().then((response) => {
if (response.status === 'connected') {
let fbToken = response.authResponse.accessToken;
this.authenticate(fbToken);
} else if( response.status === 'not_authorized') {
// code for not authrized
// this.transitionTo('/');
} else {
// code for facebook login
// this.transitionTo('/');
}
}).catch(() => {
// this.sendAction('check','/');
});
},
}
});
但是在ajax调用成功之后永远不会被调用,我无法获得响应,浏览器总是响应:
pretender.js:132 XHR finished loading: POST "http://localhost:3000/v1/sessions/fb_login".
有人请解释一下ajax如何在api中使用api调用。