I'm stuck in in the middle of something:
TL;DR = I'm sending data through a POST request, but the server responses that I'm doing a GET request
I'm working with Laravel and Angular 1.5. Basically, in the view i have something like this.
This is my view:
<form name="formCrossedRelation" novalidate role="form"
ng-submit="createCrossedRelation(delivery_carrier_status)">
<div class="row">
<div class="col-md-12">
<div class="form-group"
ng-class="{'has-error' : formCrossedRelation.configuration.$invalid && formCrossedRelation.configuration.$error.required && (formCrossedRelation.configuration.$dirty || formCrossedRelation.$submitted) , 'has-success' : formCrossedRelation.configuration.$valid || formCrossedRelation.$submitted }">
<label for="">Carrier <small class="text-danger font-noraml ">(*)</small></label>
<select
ng-model="delivery_carrier_status.delivery_carrier_status.carrier_id"
required class="form-control" name="carrier"
ng-options="item as item.name for item in carriers track by item.id"
ng-change="getExternalStatuses(delivery_carrier_status.delivery_carrier_status.carrier_id)">
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-5">
<div class="form-group"
ng-class="{'has-error' : formCrossedRelation.configuration.$invalid && formCrossedRelation.configuration.$error.required && (formCrossedRelation.configuration.$dirty || formCrossedRelation.$submitted) , 'has-success' : formCrossedRelation.configuration.$valid || formCrossedRelation.$submitted }">
<label for="">Estado Carrier <small
class="text-danger font-noraml ">(*)</small></label> <select
ng-model="delivery_carrier_status.delivery_carrier_status.id"
required class="form-control" name="externalStatuses"
ng-options="item as item.code for item in externalStatuses track by item.id">
</select>
</div>
</div>
<div class="col-md-2"></div>
<div class="col-md-5">
<div class="form-group"
ng-class="{'has-error' : formCrossedRelation.configuration.$invalid && formCrossedRelation.configuration.$error.required && (formCrossedRelation.configuration.$dirty || formCrossedRelation.$submitted) , 'has-success' : formCrossedRelation.configuration.$valid || formCrossedRelation.$submitted }">
<label for="">Estado EasyPoint <small
class="text-danger font-noraml ">(*)</small></label> <select
ng-model="delivery_carrier_status.delivery_status.id" required
class="form-control" name="EPstatus"
ng-options="item as item.name for item in delivery_statuses track by item.id">
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group"
ng-class="{'has-error' : formPudo.full_address.$invalid && formPudo.full_address.$error.required && (formPudo.full_address.$dirty || formPudo.$submitted) , 'has-success' : formPudo.full_address.$valid || formPudo.$submitted }">
<label for="">Operador 1 <small
class="text-danger font-noraml ">(*)</small></label> <input
class="form-control" name="full_address" type="text"
ng-model="delivery_carrier_status.json_aditional[1]" />
</div>
</div>
<div class="col-md-4">
<div class="form-group"
ng-class="{'has-error' : formCrossedRelation.configuration.$invalid && formCrossedRelation.configuration.$error.required && (formCrossedRelation.configuration.$dirty || formCrossedRelation.$submitted) , 'has-success' : formCrossedRelation.configuration.$valid || formCrossedRelation.$submitted }">
<label for="">Operación <small class="text-danger font-noraml ">(*)</small></label>
<select ng-model="delivery_carrier_status.json_aditional.operator"
class="form-control" name="operation"
ng-options="item for item in operations track by item.id">
</select>
</div>
</div>
<div class="col-md-4">
<div class="form-group"
ng-class="{'has-error' : formPudo.full_address.$invalid && formPudo.full_address.$error.required && (formPudo.full_address.$dirty || formPudo.$submitted) , 'has-success' : formPudo.full_address.$valid || formPudo.$submitted }">
<label for="">Operador 2 <small
class="text-danger font-noraml ">(*)</small></label> <input
class="form-control" name="full_address" type="text"
ng-model="delivery_carrier_status.json_aditional[2]" />
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button class="btn btn-orange pull-right" ladda="loading.btnCreate"
data-style="zoom-in" type="submit">Crear relación</button>
</div>
</div>
This is my controller in Angular
$scope.createCrossedRelation = function(delivery_carrier_status) {
$scope.loading.btnCreate = true;
if (this.formCrossedRelation.$valid) {
delivery_carrier_status.json_aditional = JSON.stringify(delivery_carrier_status.json_aditional);
TrackingService.createCrossedRelation(delivery_carrier_status).then(function successCallback(response) {
if (response.status == 201) {
$scope.delivery_carrier_statuses.unshift(response.data.status);
delivery_carrier_status = {};
$scope.modalcreateCrossedRelation = false;
$scope.loading.btnCreate = false;
Notification.success({
title : "¡Felicitaciones!",
message : "Correlación creada.",
template : "custom_template.html"
});
}
}, function errorCallback(response) {
$scope.loading.btnCreate = false;
if (response.status == 400) {
for (var i = 0; i < response.data.length; i++) {
Notification.error({
title : "¡Oops!",
message : response.data[i],
template : "custom_template.html"
});
}
}
});
this.formCrossedRelation.$setPristine();
} else {
$scope.loading.btnCreate = false;
Notification.error({
title : "¡Oops!",
message : 'No has completado todos los datos obligatorios del formulario.',
template : "custom_template.html"
});
}
};
This is my TrackingService file
createCrossedRelation : function(delivery_carrier_status) {
var req = {
method : 'POST',
url : '/api/statusconversion/',
dataType : 'json',
headers : {
'Content-Type' : 'application/json',
'X-Requested-With' : 'XMLHttpRequest'
},
data : delivery_carrier_status
}
return $http(req);
},
At this point, when I'm debugging, in the req variable, I'm getting this
As you can see, I'm doing a POST request
But as soon as the backend responses, it is with a 405 status: Method not allowed
This is the routes.php file
Route::post('api/statusconversion/', 'TrackingController@createDeliveryStatusCarrierStatus');
I don't know why i'm stucked. If anybody could help please.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire