2016-12-07 35 views
0

我正在使用React js(Admin on Rest)进行API调用(GET)。当API调用时出现React JS(Admin on Rest)错误

我已经检查API服务器上,当我打电话为localhost:5001 /引用,服务器返回数据的城市,但我不知道它在客户端上的错误,这里是从日志浏览器:

failure.js:18 Error: The X-Total-Count header is missing in the HTTP Response. This header is necessary for pagination. If you are using CORS, did you declare X-Total-Count in the Access-Control-Allow-Headers header? 

at convertHTTPResponseToREST (http://localhost:3000/static/js/bundle.js:33928:28) 
at http://localhost:3000/static/js/bundle.js:33966:21 

failure.js:18 Error: The Content-Range header is missing in the HTTP Response. This header is necessary for pagination. If you are using CORS, did you declare Content-Range in the Access-Control-Allow-Headers header? 

at convertHTTPResponseToREST (http://localhost:3000/static/js/bundle.js:33010:28) 
at http://localhost:3000/static/js/bundle.js:33037:21 

有人可以帮忙吗?谢谢

+0

我认为您正在使用任何Package进行分页。 我不确定后端使用了哪种技术或框架。但是您需要在Access-Control-Allow-Headers标头中为后端应用(Rails,PHP或其他)提供Content-Range。 –

+0

也许它包含在Admin on Rest框架中,我已经添加了标题,但仍然无效,或者我在设置标题时出错,我是新手在做出反应。所以你怎么看 ? – Khalid

+0

此问题与后端应用程序有关,您只需在头中允许Content-Range。您正在为beckend应用程序使用哪个框架。 –

回答

1

即使您的API仅返回结果的一个子集,为了构建分页控制器,管理静止也需要一种方法来确定总共有多少结果。例如,如果API返回10个结果,但提及总共有100个结果,那么admin-on-rest将显示10个页面链接。

simpleRestClientjsonServerRestClient都希望看到的响应报头信息,无论是在X-Total-Count,或Content-Range

如果你的API不包含这些标题,您可以:

  • 更新您的API,包括总的X-Total-Count头,或
  • 编写自己的REST客户端抢约占总数的信息其他地方的记录数量(例如在响应正文中)
相关问题