Error access-control-allow-origin on angularjs $http.post
<p>I wrote simple code with angularjs to communicate to PHP server API that I hosted in shared server before. I used $http.get and $http.post to get data from the server but it returned error 'access-control-allow-origin' like below:</p>

<pre><code>http://dpmp.arkoding.tk/index.php/api/datapost. Response to preflight request doesn't pass 
access control check: No 'Access-Control-Allow-Origin' header is present on the requested 
resource. Origin 'http://localhost:8100' is therefore not allowed access. 
The response had HTTP status code 404.
</code></pre>

<p><a href="http://i.stack.imgur.com/ODy1h.jpg" rel="nofollow">access-control-allow-origin</a></p>

<p>most of the references that I got explained that it caused by CORS enabled on server site and just simply add a line 'header('Access-Control-Allow-Origin: *');' at the top for fix it. I have done that but it just fixed '$http.get' function and I still got the same error for '$http.post'. And made me more confused because it worked if I used postman and I thought the problem was in my angular code.</p>

<p>I have tried add some code in my services.js shown on the snippets below:</p>

<pre><code>  var datac = {id: 'helo'};
  var head = {'Content-Type': 'application/json'};
  return $http({
      url: url + '/datapost',
      method: 'POST',
      headers: head,
      data: datac
  });
</code></pre>

<p>and without header</p>

<pre><code>  var datac = {id: 'helo'};
  return $http({
      url: url + '/datapost',
      method: 'POST',
      data: datac
  });
</code></pre>

<p>but it wouldn't work. I even have tried to move my rest API to another hosting provider and it also returned the same error when I used angular $http.post.
I'm very appreciated for your help to my problem,
and I am sorry for my untidy english by the way :).</p>