1
votes

view

<ion-view view-title="Dashboard">
  <ion-content class="splash padding has-header">
<p class="button button-calm  button-block" ng-click="insert()">post</p>
    </ion-content>
</ion-view>

controller $scope.insert = function() { var data = {matric:21};

  $http.post("http://localhost:8000/datas",data).success(function(data,status){
    console.log(data);
  }).error(function(error){
    console.log("error is that ",error);
  });
};

laravel routes

Route::get('datas',array('middleware' => 'cors', 'uses' => 'datasController@index'));
Route::get('datas/{level}',array('middleware' => 'cors', 'uses' => 'datasController@show'));
Route::post('datas',array('middleware' => 'cors', 'uses' => 'datasController@store'));

laravel controller

 public function store()
    {
        $dat = new Data();
        $dat->matric = input::get('matric');
        $dat->save();
    }

the error i get in my chrome log

XMLHttpRequest cannot load http://localhost:8000/datas. Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values 'http://evil.com/, *', but only one is allowed. Origin 'http://localhost:8100' is therefore not allowed access.

controllers.js:126 error is that null

the error i get in my mozilla log

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8000/datas. (Reason: CORS header 'Access-Control-Allow-Origin' missing). error is that null

2

2 Answers

2
votes

I ran a post request through postman and saw a verifycrsf tokken error.you can get through this by editin the verifycrsf.php file in your laravel file,add your paths to the function there and it should work. (for example. 'api/*' for localhost:8000/api/matric)

0
votes

Use this package, it will help you with the Cross Origin Request Protection