Comments (5)
呵呵,多参考样版工程,文档今年上半年一定会补齐的。
之所以使用头信息X-Content-Record-Total传递集合的数量是为了更好的保持语义的一致性。
list接口返回的body是一个数组,更符合程序员的思维,也更符合rest的**。
http协议并没有规定这种情况应该使用什么。这里通过 X-Content 的前缀避免冲突。
利用头信息传递重要信息是很常见的rest玩法,不过国内很多大厂都习惯把http协议当做传输协议来玩,所有的返回信息都放在 response.body 里。
from open-rest.
放到头里面,本身也没什么问题,就是取出来有些麻烦,比如:jQuery的自带的ajax,虽然有 jqXHR .getResponseHeader() 方法,但是取不出来值,不知道具体原因是啥。
也许时jQuery库的问题。
这个不是大问题,保持统一性,简洁性也好。
from open-rest.
应该是大小写的问题,获取的时候全部用小写字母试试看。
from open-rest.
还是取不到,这不是个重要的问题,问题不大。我在后台重新把total放到数据里了,一般人比较适应这个。呵呵。
原始的头信息是这样的:
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
X-Content-Record-Total: 3
Content-Type: application/json; charset=utf-8
Content-Length: 662
Date: Tue, 21 Mar 2017 04:04:14 GMT
Connection: keep-alive
取头信息的方法,还有一个getAllResponseHeaders是获取所有的头。只获取到了: "Content-Type: application/json; charset=utf-8
"
代码如下,无论大小写,获取的都是null。
import Ajax from 'robe-ajax'
const { param } = Ajax
console.log(response,response.getAllResponseHeaders(),response.getResponseHeader("X-Content-Record-Total"),response.getResponseHeader("x-content-record-total"));
Object {readyState: 4, responseText: "{"data":[{"id":1,"isDelete":"no","clientIp":"","cr…pdatedAt":"2017-03-20T14:57:23.000Z"}],"count":3}", responseJSON: Object, status: 200, statusText: "OK"} "Content-Type: application/json; charset=utf-8
" null null
from open-rest.
很不可思议,你到 robe-ajax 项目下反馈看看。没道理呀。我们公司所有产品都这么用,获取完全没问题。
from open-rest.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from open-rest.