Using xhr.getResponseHeader to get Total # of Records
Using xhr.getResponseHeader to get Total # of Records
timcadieux
Posts: 76Questions: 22Answers: 0
Using serverside to return content from an api. The Total RecordCount is returned in the Response header..
you can see here
Attemptinng to use xhr.getResponseHeader('total'); but it's always null..i must be missing something super simple.
ideas?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I'm not seeing that. The only response returned in your fiddle is the data array. The protocol is discussed here.
Cheers,
Colin
It seems like you're telling me to change how the content is returned to me, I cannot.
If you load the Bin in Chrome, use F12, goto Network Tab, XHR, Refresh, click on the List call and you will see the total of 199 returned in the Response Headers.
Just trying to access it.
It seems like the only response header in the
xhr
object isconten-header
accroding to thegetAllResponseHeaders()
. Not sure why though:http://live.datatables.net/ligoroba/2/edit
Hopefully @allan or @colin can tell us why.
Kevin
I believe this is a security protection by the browser since the
access-control-expose-headers
property is not being set by the server. You need to have the server include:for it to work.
With that done, Kevin's solution should work.
Allan
Yeah, I already have this in my .netCore startup but I can't read the total.
I've created a .netCore Cors related StackOverflow question to try and figure it out.
services.AddCors(options => options.AddPolicy("ApiCorsPolicy", build => build
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()));