using backbone to put data into rest server

2019-06-11 01:09发布

I have a question.

If i have a model named Input. It contains model Invoice and Collection InvoiceDetailCollection.

I modified the backbone.js specifically create:"POST" into create:"PUT" inorder to allow PUT since my service doesn't use POST.

If i were to use Input.save() What should my server expect as a request? I mean already have set a service method to expect string since if i expect string i can't use the input.save();

What should be the right parameter i should expect on my server side if i were to use the Input.save() method of backbone.js

1条回答
相关推荐>>
2楼-- · 2019-06-11 02:00

By default, Backbone sends application/json data and the server should expects JSON data. You'll want to decode it. I use PHP and middleware that automatically json_decode($data) and turns it into an associative array for me to manipulate.

If this isn't possible, (can't take JSON data) I think what you want is to use emulateJSON It will serialize your data and send it as application/x-www-form-urlencoded like an HTML form.

http://documentcloud.github.com/backbone/#Sync-emulateJSON

查看更多
登录 后发表回答