我试图通过angularjs发送一个put请求。我的应用程序接收器正在运行laravel。
当我尝试发送请求时,我收到以下错误消息:
TypeError: Cannot set property '_method' of undefined
at $http.transformRequest (http://localhost:8000/js/controller-university.js:91:28)
at transformData (http://localhost:8000/js/libs/angular/angular.js:7433:12)
at serverRequest (http://localhost:8000/js/libs/angular/angular.js:8071:23)
at wrappedCallback (http://localhost:8000/js/libs/angular/angular.js:11572:81)
at wrappedCallback (http://localhost:8000/js/libs/angular/angular.js:11572:81)
at http://localhost:8000/js/libs/angular/angular.js:11658:26
at Scope.$eval (http://localhost:8000/js/libs/angular/angular.js:12701:28)
at Scope.$digest (http://localhost:8000/js/libs/angular/angular.js:12513:31)
at Scope.$apply (http://localhost:8000/js/libs/angular/angular.js:12805:24)
at HTMLFormElement.<anonymous> (http://localhost:8000/js/libs/angular/angular.js:19139:23)
这是我的代码:
update : function(data) {
return $http({
method: 'POST',
url: '/api/university'+data.id,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: $.param(data)
transformRequest: function(data){
data._method = 'PUT';
return data;
}
});
},
有什么问题?
答案 0 :(得分:0)
这里有正确的代码:
update: function(data){
return $http({
method: 'PUT',
url: '/api/university/'+data.id,
data: $.param(data),
headers: { 'Content-Type' : 'application/x-www-form-urlencoded' }
});
},
答案 1 :(得分:0)
var request = {
method: 'put',
url: '/admin/banners/'+$scope.editid,
data: fields,
headers: {
'Content-Type':'application/json'
}
};
它对我有用。