# Angularjs Post Request CORS issue

**URL:** <https://forum.ionicframework.com/t/angularjs-post-request-cors-issue/10334>\
**Category:** ionic-v1\
**Created:** [September 28, 2014, 7:37am UTC](https://forum.ionicframework.com/t/angularjs-post-request-cors-issue/10334 "2014-09-28T07:37:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![summermick](https://avatars.discourse-cdn.com/v4/letter/s/9e8a1a/32.png) [@summermick](https://forum.ionicframework.com/u/summermick)\
**Post date:** [September 28, 2014, 7:37am UTC](https://forum.ionicframework.com/t/angularjs-post-request-cors-issue/10334/1 "2014-09-28T07:37:43Z")

</div>

```
$http.post('http://localhost:8000/api/item/', {
           some json
        }).success(function (data) {
            console.log(data);
        });

```

angularjs seems not working properly with cross domain.  
keeps throwing this "XMLHttpRequest cannot load [http://localhost:8000/api/item/](http://localhost:8000/api/item/). No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘[http://localhost:8100](http://localhost:8100)’ is therefore not allowed access. "

also, enable cors plugin in chrome still gives an error "Request header field Content-Type is not allowed by Access-Control-Allow-Headers. "

```
$http({
        method: 'POST',
        url: 'http://localhost:8000/api/item',
        data: {
           some json
        },
        headers: {'Content-Type': undefined}
    
    });

```

using this code produce 500 internal error. Is there anyone know how to fix this? by the way, I also tried to add $httpproivder to enable cors that apparently is not working either.

however, $ajax works like charm.

```
$.post('http://localhost:8000/api/item/', {some json}).done(
            function (data) {
                console.log(data);
            }
        );
```

---

<div class="post-metadata">

**Author:** ![nicraboy](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/nicraboy/32/6917_2.png) [@nicraboy](https://forum.ionicframework.com/u/nicraboy)\
**Post date:** [September 28, 2014, 1:05pm UTC](https://forum.ionicframework.com/t/angularjs-post-request-cors-issue/10334/2 "2014-09-28T13:05:42Z")

</div>

Hi @summermick,

You shouldn’t have CORS issues when running on the device. CORS problems are browser only.

In your **web server** if you allow all origins (\*), the error should go away in the browser.

See more information here:

> **[Bypass CORS Errors When Testing APIs Locally](https://www.thepolyglotdeveloper.com/2014/08/bypass-cors-errors-testing-apis-locally/)**
>
> Make configuration changes to your web browser or run a local server to bypass CORS and other cross origin problems when testing APIs locally.

---

<div class="post-metadata">

**Author:** ![summermick](https://avatars.discourse-cdn.com/v4/letter/s/9e8a1a/32.png) [@summermick](https://forum.ionicframework.com/u/summermick)\
**Post date:** [September 28, 2014, 10:30pm UTC](https://forum.ionicframework.com/t/angularjs-post-request-cors-issue/10334/3 "2014-09-28T22:30:27Z")

</div>

thanks nicaboy.  
I pretty much gave up.

---

<div class="post-metadata">

**Author:** ![alexmanfro1981](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/alexmanfro1981/32/92257_2.png) [@alexmanfro1981](https://forum.ionicframework.com/u/alexmanfro1981)\
**Post date:** [October 9, 2015, 4:02pm UTC](https://forum.ionicframework.com/t/angularjs-post-request-cors-issue/10334/4 "2015-10-09T16:02:37Z")

</div>

i had same problem on device emulated and via ionic serve  
,the problem is cors for sure i tried to use this angular code but it not work ,but the solution is near something like this:

```
   $http.get('http://webservice:8080/services/webservices/testservice',
		            {
		            headers: {
		                'Content-Type': 'application/json' , 
		                'Access-Control-Allow-Origin': '*',
		                'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
		                'Access-Control-Allow-Headers':'X-Requested-With'	
		            }
		        }).success(function(response) {
		           alert("Ok");

		        }).
	            error(function (data, status) {
	                alert(JSON.stringify(data));
	                alert(JSON.stringify(status));
	            });

```

the request never start from the app becouse i tested with a breakpoint on the webservice rest implementation and it never stop ,that mean no request sended by browser

---

<div class="post-metadata">

**Author:** ![evaflow](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@evaflow](https://forum.ionicframework.com/u/evaflow)\
**Post date:** [December 4, 2015, 2:31am UTC](https://forum.ionicframework.com/t/angularjs-post-request-cors-issue/10334/5 "2015-12-04T02:31:08Z")

</div>

Nic, I know you said there should be no CORS issues but I don’t know what else my problem could be and it’s sooo frustrating … I’ve been searching and searching I don’t know what’s going on… I keep getting a status:0 error message with the following code:

$scope.feedlyApi = function() {

```
var req = {
	method: 'GET',
	url: "http://sandbox.feedly.com/v3/search/feeds",
	params: {
		'query': 'nursing'
	},
	headers: {
	      'Content-Type': 'application/json' , 
	       'Access-Control-Allow-Origin': '*',
	        'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
	      'Access-Control-Allow-Headers':'X-Requested-With'	
	 }		
}

$http(req).success(function(res) {
	console.log(res);
	console.log('Success', angular.toJson(res.data));
}).error(function(err){
	console.error(angular.toJson(err))
})

```

}

I added the chrome plugin to enable CORS and the API request is successful when i use ionic serve however when i run ionic emulate --live reload I can’t get it to work

---

<div class="post-metadata">

**Author:** ![Thesurya9](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/thesurya9/32/117460_2.png) [@Thesurya9](https://forum.ionicframework.com/u/Thesurya9)\
**Post date:** [September 23, 2016, 1:22pm UTC](https://forum.ionicframework.com/t/angularjs-post-request-cors-issue/10334/6 "2016-09-23T13:22:46Z")

</div>

You can use thins plugin too for solving browser related problem —\>\>

> **[Allow-Control-Allow-Origin: \*](https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en)**
>
> Allows to you request any site with ajax from any source. Adds to response 'Allow-Control-Allow-Origin: \*' header
