我正在尝试使用DS.RESTAdapter
和express来模拟调用,使用ember-cli构建todoMVC。然而,当我尝试保存新的待办事项时,控制台会出现以下错误:
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中创建代办事项的create操作:
actions:
createTodo: ->
return unless title = @get('newTitle')?.trim()
@set('newTitle', '')
@store.createRecord('todo',
title: title
isCompleted: false
).save()
任何帮助都会非常感激。我对express不熟悉,也不确定为什么jquery不喜欢它返回的201。
end()
不必要,因为已经使用了send()
。据我所知,只能选择其中一个,而不能同时使用两者。 - marksyzm