2016-07-22 66 views
1

这是我的离子视图发布数据给出错误

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

我的角代码

$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路由

Route::get('datas',array('middleware' => 'cors', 'uses' => '[email protected]')); 
Route::get('datas/{level}',array('middleware' => 'cors', 'uses' => '[email protected]')); 
Route::post('datas',array('middleware' => 'cors', 'uses' => '[email protected]')); 

我laravel控制器

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

我在铬日志得到错误

的XMLHttpRequest无法加载http://localhost:8000/datas。响应于 预检请求未通过访问控制检查: “访问控制允许来源”报头包含多个值 “http://evil.com/,*”,但只有一个是允许的。因此不允许访问原产地 'http://localhost:8100'

controllers.js:126错误是空

错误我在Mozilla浏览器日志得到

跨来源请求阻止:同源策略不允许读 远程资源的http://localhost:8000/datas。 (原因:缺少CORS 头'Access-Control-Allow-Origin')。错误是空

回答

2

我跑通过邮递员POST请求,看到一个verifycrsf tokken error.you可以通过editin的度过这次难关在你的laravel文件中加入verifycrsf.php文件,把你的路径添加到那里的函数中,它应该可以工作。 (例如。'api/*'为localhost:8000/api/matric)

+0

这让我绊倒了一段时间 - 这是我在Laravel 5.3中的解决方法 – Phil

0

使用this包,它会帮助你与跨源请求保护

+0

am已经在使用这个(barryvdh/laravel-cors)软件包... – Nipek

+0

我仍然得到相同的错误。我是使用laravel5.2 – Nipek