如何从 URL 请求不符合 Ember.js 的?

How to request from URL that is not Ember.js-conform?

我们的聊天应用程序的导航栏中需要显示未读计数。可以在URL:

下申请
.../chats/get_unread_count

响应如下:

{
 "unread": 0
}

由于URL不符合Ember.js标准,我不确定如何让Ember在URL下请求它。我 运行 没有想法尝试所以我希望你能帮助我。

对于此类内容,我们有 ember-ajax。您可以在您的组件中导入此服务,然后像以前在例如 ajax 中进行调用一样使用它jQuery

这是一个例子:

export default Ember.Component.extend({
  ajax: Ember.inject.service(),

  actions:  {
    makeRequest(params) {
      this.get('ajax').request('/chats/get_unread_count', {data: {params: params}}).
        then((repsonse) => {
          this.set('unreadCounts', response.unread);
        });
    }
  }