How to submit the Ionic frame work form in Laravel 5.2 controller using post request -
this ionic view
<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>
angular controller
$scope.submit = function() { $http({ method: 'post', url: 'http://203.193.173.125:8001/updateprofile', data:$scope.userprofile }).success(function (response) {console.log(response) }); }
laravel middleware cors
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") { // client-side application can set headers allowed in access-control-allow-headers return response::make('ok', 200, $headers); } $response = $next($request); foreach($headers $key => $value) $response->header($key, $value); return $response; }
i have initialized cors in kernal.php
'cors' => \app\http\middleware\cors::class,
in laravel routing
route::group(['middleware' => 'cors'], function(){ route::post('/updateprofile', 'mobile\rotaryindiacontroller@updateprofile');
}
public function updateprofile(request $request) { $data =$request->all(); print_r($data); }
i getting issue when submitted :
xmlhttprequest cannot load http://203.193.173.125:8001/updateprofile. response preflight request doesn't pass access control check: 'access-control-allow-origin' header has value 'http://203.193.173.125:8001' not equal supplied origin. origin 'http://10.90.90.145:8100' therefore not allowed access.
any once can me.thanks in advance
Comments
Post a Comment