这是我的离子观点
<form name="Profileform" novalidate ng-submit="submit()">
<div class="row row-center">
<div class="col text-center">
<div class="hero" style="background-image: url('img/profile-bg1.jpg');">
<div class="content">
<div class="avatar" style="background-image: url(http://203.193.173.125:8001/assets/images/{{userprofile.image}});"></div>
<h3><a class="light">{{userprofile.name}}</a></h3>
<h4>{{userprofile.mobile}}</h4>
</div>
</div>
</div>
</div>
<div class="row row-center">
<div class="col">
<label class="item item-input">
<span class="input-label">Mobile No:</span>
<input type="text" id="mobile" name="mobile" ng-model="userprofile.mobile" required readonly >
</label>
<label class="item item-input">
<span class="input-label">Name</span>
<input type="text" id="name" name="name" ng-model="userprofile.name" required >
</label>
<label class="item item-input">
<span class="input-label">Email</span>
<input type="email" id="email" name="email" ng-model="userprofile.email" >
</label>
<label class="item item-input">
<span class="input-label">DateOfBirth</span>
<input type="text" id="dob" name="dob" ng-model="userprofile.dob" >
</label>
<label class="item item-input">
<span class="input-label">Address</span>
<input type="text" id="address" name="address" ng-model="userprofile.address" >
</label>
<lable class="item">
<span class="input-label" >Gender</span>
<ion-radio name='gender' ng-model='userprofile.gender' value="0" ng-checked ='userprofile.gender =="0"'>Male</ion-radio>
<ion-radio name='gender' ng-model='userprofile.gender' value="1" ng-checked ='userprofile.gender =="1"'>FeMale</ion-radio>
</lable>
<lable class="item">
<!-- {{userprofile.classification}} -->
<span class="input-label" > Classfication </span>
<ion-radio class="ink" name='classification' ng-model='userprofile.classification' value="employee" ng-checked ='userprofile.classification =="employee"'>employee</ion-radio>
<ion-radio class="ink" name="classification" ng-model='userprofile.classification' value="bussiness" ng-checked ="userprofile.classification == 'bussiness'" >bussiness</ion-radio>
<ion-radio class="ink" name="classification" ng-model='userprofile.classification' value="others" ng-checked ="userprofile.classification == 'others'">others</ion-radio>
</lable>
<lable class="item">
<span class="input-label" >Interests</span>
<ion-checkbox ng-repeat="interest in userprofile.interests" ng-checked="interest.checked =='true'" ng-model="interest.checked">{{interest.name}}
</ion-checkbox>
</lable>
<button type="submit" class="button button-block button-positive ink">Save</button>
</div>
</div>
</form>
角度控制器
$scope.submit = function()
{ $http({
method: 'POST',
url: 'http://203.193.173.125:8001/updateprofile',
data:$scope.userprofile
}).success(function (response)
{console.log(response)
});
}
Laravel中间件角色
public function handle($request, Closure $next)
{
header("Access-Control-Allow-Origin: *");
// ALLOW OPTIONS METHOD
$headers = [
'Access-Control-Allow-Methods'=> 'POST, GET, OPTIONS, PUT, DELETE',
'Access-Control-Allow-Headers'=> 'ACCEPT, Content-Type, X-Auth-Token, Origin, X-CSRF-TOKEN, X-Custom-Header, X-Auth-Token',
'Access-Control-Max-Age'=> 1728000
];
if($request->getMethod() == "OPTIONS") {
// The client-side application can set only headers allowed in Access-Control-Allow-Headers
return Response::make('OK', 200, $headers);
}
$response = $next($request);
foreach($headers as $key => $value)
$response->header($key, $value);
return $response;
}
我已经在kernal.php中初始化了我的角色
'cors' => \App\Http\Middleware\Cors::class,
在我的laravel路由
中 Route::group(['middleware' => 'cors'], function(){ Route::post('/updateprofile', 'Mobile\RotaryIndiaController@updateprofile');
}
public function updateprofile(Request $request)
{
$data =$request->all();
print_r($data);
}
我在提交时遇到问题:
XMLHttpRequest无法加载http://203.193.173.125:8001/updateprofile。对预检请求的响应未通过访问控制检查:“访问控制 - 允许 - 来源”&#39;标头的值为&#39; http://203.193.173.125:8001&#39;这不等于提供的原产地。起源&#39; http://10.90.90.145:8100&#39;因此不允许访问。
任何一次可以帮助我。谢谢你提前