如何解决:
可能未处理的拒绝:{“ data”:null,“ status”:-1,“ config”:{“ method”:“ POST”,“ transformRequest”:[null],“ transformResponse”:[null], “ jsonpCallbackParam”:“回调”,“ url”:“ http://localhost:8000/api/image”,“ data”:{“ felhasznalonev”:“ fdgfgfg”},“ headers”:{“ Accept”:“ application / json,text /普通的 / “,” Content-Type“:” application / json; charset = utf-8“}},” statusText“:”“,” xhrStatus“:”错误“}
Angularjs控制器:
这是我的AngularJS控制器
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
var BACKEND_URL = "http://localhost:8000";
$scope.regSubmit = function(){
$http({
method: "POST",
url:BACKEND_URL + '/api/image',
data: {felhasznalonev: $scope.felhasznalonev},
}).then(function(data){
alert(data.msg)
});
}
});
laravel路线: 这条我的幼虫路线
Route::post('api/image' , 'AdmindashController@uploadImage');
laravel控制器
public function uploadImage(){
$input = Input::json();
$input_array = (array)$input;
$rules = array(
'felhasznalonev' => 'required'
);
$val = Validator::make($input_array, $rules);
if(! $val->fails() ) {
$data = array('msg' => 'all good');
} else {
$data = array('msg' => $val->errors->all());
}
return Response::json($data);
}