Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.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
Jquery 如何使用Express返回格式良好的201?_Jquery_Ember.js_Express_Ember Cli - Fatal编程技术网

Jquery 如何使用Express返回格式良好的201?

Jquery 如何使用Express返回格式良好的201?,jquery,ember.js,express,ember-cli,Jquery,Ember.js,Express,Ember Cli,我正在尝试使用ember cli构建todoMVC,使用DS.RESTAdapter和express模拟调用。我遇到的问题是,当我尝试保存新todo时,我在控制台中看到以下错误: SyntaxError: Unexpected end of input at Object.parse (native) at jQuery.parseJSON (http://localhost:4200/assets/vendor.js:8717:22) at ajaxConvert (h

我正在尝试使用ember cli构建todoMVC,使用
DS.RESTAdapter
和express模拟调用。我遇到的问题是,当我尝试保存新todo时,我在控制台中看到以下错误:

SyntaxError: Unexpected end of input
    at Object.parse (native)
    at jQuery.parseJSON (http://localhost:4200/assets/vendor.js:8717:22)
    at ajaxConvert (http://localhost:4200/assets/vendor.js:9043:19)
    at done (http://localhost:4200/assets/vendor.js:9461:15)
    at XMLHttpRequest.jQuery.ajaxTransport.send.callback (http://localhost:4200/assets/vendor.js:9915:8)
我很确定问题在于,当我在新创建的模型上调用
save()
时,它正在向/发送一个post请求,express正在回复此请求:

 todosRouter.post('/', function(req, res) {
    res.status(201).end();
  });
以下是Ember中创建todo的创建操作:

actions:
    createTodo: ->
      return unless title = @get('newTitle')?.trim()

      @set('newTitle', '')
      @store.createRecord('todo',
        title: title
        isCompleted: false
      ).save()

任何帮助都将不胜感激。我是新手,不知道为什么jquery不喜欢它返回的201。

问题是它试图在空白响应上解析JSON。它有效地执行了
jQuery.parseJSON(“”)
——如果您尝试运行它,就会产生错误

要解析它,您可以返回任何可以解析为JSON的字符串,例如字符串
null
或空引号


谢谢这正是问题所在。jQuery需要一个响应主体,但没有得到响应主体。我认为
end()
应该没有必要,因为使用了
send()
。不是一个就是另一个,不是两个都是。
todosRouter.post('/', function(req, res) {
  res.send('null');
  res.status(201).end();
});

todosRouter.post('/', function(req, res) {
  res.send('""');
  res.status(201).end();
});