Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 在路由器模型中调用多个ajax时未捕获(承诺中)_Ember.js_Ember Cli - Fatal编程技术网

Ember.js 在路由器模型中调用多个ajax时未捕获(承诺中)

Ember.js 在路由器模型中调用多个ajax时未捕获(承诺中),ember.js,ember-cli,Ember.js,Ember Cli,我在ember路由器模型中调用多个API端点 我正在使用ember cli 3.11.0 当我刷新页面时,它无法加载“Uncaught(in promise)”,这一点具体在$.ajax调用中 import $ from 'jquery'; import { hash } from 'rsvp'; export default Route.extend(AuthenticatedRouteMixin, { model: function (param) { return hash(

我在ember路由器模型中调用多个API端点 我正在使用ember cli 3.11.0 当我刷新页面时,它无法加载“Uncaught(in promise)”,这一点具体在$.ajax调用中

import $ from 'jquery';
import { hash } from 'rsvp';

export default Route.extend(AuthenticatedRouteMixin, {
  model: function (param) {
    return hash({
      category: $.ajax({
        url: 'http://localhost:8000/catalog/category/' + param.id,
        type: 'GET'
      }).then(function(res) {
        return res;
      }),
      categories: $.ajax({
        url: 'http://localhost:8000/catalog/category',
        type: 'GET'
      }).then(function(res) {
        return res;
      })
    })
  }
});
有了这些代码,我想在setupController内部调用

setupController(ctrl, model) {
   console.log(model.category);
   console.log(model.categories);
}

Ola@ave您不使用的原因是什么,这是Ember默认蓝图的一部分?是否有任何关于错误的信息未被捕获?如果是这样,您应该捕获并记录错误以收集其他信息。网络请求的结果是什么?如果它没有返回
200
或不是有效的json,但包含
内容类型:application/json
header
jQuery.ajax()
将抛出。我建议对新应用程序使用而不是
jQuery.ajax()
。这是因为我使用的是UTIL调用jQuery.ajax()的遗留代码,我想我必须重构这些ajax(),并用错误替换它,因为在模型中,param属性与路由器中声明的param名称不匹配,愚蠢的我:D谢谢你的提示谢谢你的代码片段,我将使用fetch代替
ember fetch
不仅是关于IE11的polyfill,而且还提供了更好的测试支持。如果没有余烬,提取测试将不会在进入已解决状态之前等待要解决的提取请求。例如,
wait click('button')
将在该单击触发的获取请求得到解决之前得到解决。非常有趣@jelhan!我每天都学新东西