title: How to post JSON data to REST Webservice in AngularJS
body: <p>How to post JSON data to web-service via AngularJS
  here is the code snippet</p>
  
  <pre><code>.controller('MessagePostCtrl', function($scope, $http) {
      $scope.postMessage = function() {
          var msg = document.getElementById('message').value;
          var msgdata = {
                  message : msg
              };
          var res = $http.post('http://&lt;domain-name&gt;/messenger/api/posts/savePost',msgdata);
          res.success(function(data, status, headers, config) {
              console.log(data);
          });
      }
  })
  </code></pre>
  
  <blockquote>
    <p>OPTIONS http:///messenger/api/posts/savePost<br>
    ionic.bundle.js:16185(anonymous function) ionic.bundle.js:16185
    sendReq ionic.bundle.js:15979 serverRequest ionic.bundle.js:15712
    wrappedCallback ionic.bundle.js:19197 wrappedCallback
    ionic.bundle.js:19197(anonymous function) ionic.bundle.js:19283
    Scope.$eval ionic.bundle.js:20326 Scope.$digest ionic.bundle.js:20138
    Scope.$apply ionic.bundle.js:20430(anonymous function) 
    ionic.bundle.js:43025(anonymous function)  ionic.bundle.js:10478
    forEach ionic.bundle.js:7950 eventHandler ionic.bundle.js:10477
    triggerMouseEvent ionic.bundle.js:2648 tapClick ionic.bundle.js:2637
    tapMouseUp ionic.bundle.js:2707</p>
    
    <p>XMLHttpRequest cannot load
    http:///messenger/api/posts/savePost. Invalid HTTP
    status code 404</p>
  </blockquote>
  
  <p>But when I remove the msgdata from $http.post method, everything is working fine.
  Can anyone tell me where the issue is or else guide me how to send JSON data to web-service</p>
  
  <p>Thanks for the help</p>
  
  <pre><code>**Edited:
  The Issue was with the CORS, Im using codeigniter REST Controller for web-services.
  Modified the headers. If anyone has the same issue add the below header in the construct
  
  header("Access-Control-Allow-Origin: *");
  header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
  header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method");
  if ( "OPTIONS" === $_SERVER['REQUEST_METHOD'] ) {
  die();
  }
  Thanks to Linial for the break-through, telling me where the issue is.**
  </code></pre>