jquery - How can I return a well formatted 201 with Express? -


i'm trying build todomvc ember-cli using ds.restadapter , express mock out calls. issue i'm getting when try save new todo see error in console:

syntaxerror: unexpected end of input     @ object.parse (native)     @ jquery.parsejson (http://localhost:4200/assets/vendor.js:8717:22)     @ ajaxconvert (http://localhost:4200/assets/vendor.js:9043:19)     @ done (http://localhost:4200/assets/vendor.js:9461:15)     @ xmlhttprequest.jquery.ajaxtransport.send.callback (http://localhost:4200/assets/vendor.js:9915:8) 

i'm pretty sure issue when call save() on newly created model, sending post request / express replying this:

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

here's create action in ember that's creating todo:

actions:     createtodo: ->       return unless title = @get('newtitle')?.trim()        @set('newtitle', '')       @store.createrecord('todo',         title: title         iscompleted: false       ).save() 

any appreciated. i'm new express , not sure why jquery doesn't 201 returning.

the problem it's trying parsejson on blank response. it's doing jquery.parsejson('') - produce error if try run it.

to resolve return string can parsed json - e.g. string null or empty quotes "".

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

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -