1

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 Answers 2

2

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)

Sign up to request clarification or add additional context in comments.

1 Comment

This tripped me up too for a while - this was the workaround for me in Laravel 5.3
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.