There is a website written on angular, using rest api, api gives json, ngresource takes, everything is fine, as long as all the action takes place on one server.

Ngresource works on ajax, therefore, when trying to receive or send data to another server, there will be an error in the rights. You can use jsonP, but then you have to rewrite

var resource = $resource(url, {callback: "JSON_CALLBACK"}, { get: {method: "JSONP"} } ); 

The whole meaning of rest api is traced, the post, get, delete, put headers are used there.

And the question appeared when I tried to assemble a mobile application in cordova + ionic.

You can, of course, cut down Access-Control-Allow-Origin on the server.

 <?php header('Access-Control-Allow-Origin: *'); ?> 

If someone knows the correct way, tell me.

  • In general, the mobile application should not care about Access-Control-Allow-Origin - Grundy
  • @Grundy when debugging, it starts up in the browser, and when I compile, I understand it turns out to be some kind of simplified version of the browser - Serge Esmanovich
  • when compiling, the native application should have been obtained, and when debugging in the browser, what URL is written? - Grundy
  • @Grundy ionic serve localhost: 8100 - Serge Esmanovich
  • Yeah, well, at least for debugging you can prescribe something like 'Access-Control-Allow-Origin: localhost:8100' Did you try to start the already assembled application? - Grundy

1 answer 1

A plugin for chrome helped me in debugging Ionic applications: https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi

  • I will try to use - Serge Esmanovich