简体   繁体   English

带有Json服务器的Extjs应用程序无法正常工作

[英]Extjs application with Json-server not working fine

I have a small app and I am using Rest Proxy. 我有一个小应用程序,正在使用Rest Proxy。 I set up json-server https://github.com/typicode/json-server locally. 我在本地设置了json-server https://github.com/typicode/json-server

I have not changed anything in server settings. 我没有更改服务器设置中的任何内容。 I am able to successfully GET data from server but when I try to create data like this 我能够从服务器成功获取数据,但是当我尝试创建这样的数据时

var people = App.model.myModel;

var ed = new people({"id": 2,"title": "test","body": "test"});
ed.save();

Error appears in browser console is 浏览器控制台中出现错误是

PUT http://localhost:3000/posts/11?_dc=1427464731634 404 (Not Found) PUT http:// localhost:3000 / posts / 11?_dc = 1427464731634 404(未找到)

Can some one point out why it is trying to PUT data and not POST data ? 有人可以指出为什么它尝试PUT数据而不是POST数据吗?

I found the problem my self. 我发现了自己的问题。 I was sending the "id" as well and it was looking for a post with Id 2, and obviously that doesn't exist. 我也发送了“ id”,它正在寻找带有ID 2的帖子,显然这并不存在。

var people = App.model.myModel;
var ed = new people({"title": "test","body": "test"});
ed.save();

Works perfectly 完美运作

PUT is used to update an item, Not Create. PUT用于更新项目“不创建”。

As you have specified an id value ExtJs will presume that you need to update the record rather than create it, therefore making the PUT request. 指定ID值后,ExtJs将假定您需要更新记录而不是创建记录,因此发出了PUT请求。

Most RESTful API's will provide GET, PUT, POST and sometimes DELETE, LINK Endpoints for each entity. 大多数RESTful API都会为每个实体提供GET,PUT,POST,有时还提供DELETE,LINK端点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM