jquery - breezejs inlineCount is not working (CORS cross domain http request) -


here's query:

 var query = breeze.entityquery                 .from("mandates").skip(offset).take(pagesize).inlinecount(true);          return manager.executequery(query); 

in response headers, can see count returned server:

x-inlinecount:63 

however, in succeed handler when do:

 var results = data.results;  var recordcount = data.inlinecount; 

results contains correct records. data.inlinecount null.

how come ?

edit

getallresponseheaders not return headers ! i've noticed of them missing, including x-inlinecount.

i believe because i'm doing cross-domain http request (website in localhost webapi (web service) on server on domain). how can fixed ?

i had same problem. have configure server expose x-inlinecount header. if using project asp .net web api have put next lines in web.config:

  <system.webserver>     <httpprotocol>       <customheaders>         <add name="access-control-allow-origin" value="*" />         <add name="access-control-allow-headers" value="origin, x-requested-with, content-type, accept" />         <add name="access-control-allow-methods" value="get,post,options" />         <add name="access-control-expose-headers" value="x-inlinecount" />       </customheaders>     </httpprotocol> 

also, had problem firefox, in last version of firefox, problem solved.

(yo don't need use lines, it's example) ;)

-----edit-----

i had forgotten, because log time ago. browser ,when doing cors call, sends first option call check if possible cors call , things allowed. have implement message handler in web api project manage option call. implementation next:

public class optionshttpmessagehandler : delegatinghandler     {         protected override task<httpresponsemessage> sendasync(             httprequestmessage request, cancellationtoken cancellationtoken)         {             if (request.method == httpmethod.options)             {                 var apiexplorer = globalconfiguration.configuration.services.getapiexplorer();                   var controllerrequested = request.getroutedata().values["controller"] string;                 var supportedmethods =  apiexplorer.apidescriptions                     .where(d =>                     {                          var controller = d.actiondescriptor.controllerdescriptor.controllername;                         return string.equals(                             controller, controllerrequested, stringcomparison.ordinalignorecase);                     })                     .select(d => d.httpmethod.method)                     .distinct();                  if (!supportedmethods.any())                     return task.factory.startnew(                         () => request.createresponse(httpstatuscode.notfound));                  return task.factory.startnew(() =>                 {                     var resp = new httpresponsemessage(httpstatuscode.ok);                     resp.headers.add("access-control-allow-origin", "*");                     resp.headers.add("access-control-allow-headers", "x-requested-with, content-type, accept, security,token-access");                     resp.headers.add("access-control-allow-methods", "get,post,options");                     resp.headers.add("access-control-expose-headers", "x-inlinecount");                      return resp;                 });             }              return base.sendasync(request, cancellationtoken);         }     } 

you can omit next section if put in web.config.

resp.headers.add("access-control-allow-origin", "*"); resp.headers.add("access-control-allow-headers", "x-requested-with, content-type, accept, security,token-access"); resp.headers.add("access-control-allow-methods", "get,post,options"); resp.headers.add("access-control-expose-headers", "x-inlinecount"); 

i hope solve problem.

pd: sorry english, not first language.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -