最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - configure angularjs module to send patch request - Stack Overflow

programmeradmin2浏览0评论

I am totally new to AngularJs. I am trying to send a PATCH request using Angularjs to Django Tastypie API's. My code is

var module = angular.module('myApp', []);

module.config(function ($httpProvider) {
});

function MyController($scope,$http)
{
$scope.patchCall=function(){
    $http({
    url: "/patchrequest/",
    data:data,
    method: "PATCH",
})
.success(function(data){
    console.log("SUCCESS");
    $scope.list = data.items;
}).error(function() {
    console.log("FAIL");
});
}
}

But when I am trying to send a request using this code I am Getting an error that http.patch is not a function. Tell me how can i configure ng-app and services to send a PATCH request using AngularJs. I read PATCH request is available in $resource so i tired it with $resource also. But find the same result. Please guide me how can i configure an app from scratch to send CRUD requests, specially PATCH request

I am totally new to AngularJs. I am trying to send a PATCH request using Angularjs to Django Tastypie API's. My code is

var module = angular.module('myApp', []);

module.config(function ($httpProvider) {
});

function MyController($scope,$http)
{
$scope.patchCall=function(){
    $http({
    url: "/patchrequest/",
    data:data,
    method: "PATCH",
})
.success(function(data){
    console.log("SUCCESS");
    $scope.list = data.items;
}).error(function() {
    console.log("FAIL");
});
}
}

But when I am trying to send a request using this code I am Getting an error that http.patch is not a function. Tell me how can i configure ng-app and services to send a PATCH request using AngularJs. I read PATCH request is available in $resource so i tired it with $resource also. But find the same result. Please guide me how can i configure an app from scratch to send CRUD requests, specially PATCH request

Share Improve this question asked Nov 30, 2013 at 21:05 Sajid AhmadSajid Ahmad 1,1444 gold badges18 silver badges41 bronze badges 3
  • What version of Angular are you using? – joews Commented Nov 30, 2013 at 21:12
  • how are you calling the request? Can't see how you would get error http.patch is not a function – charlietfl Commented Nov 30, 2013 at 21:12
  • I am using AngularJs 1.1.5- min.js. I am callding the request is on button click . here i sent a request using Http. but when now i m reading somewhere there written it will go using ngResource. – Sajid Ahmad Commented Nov 30, 2013 at 21:28
Add a comment  | 

1 Answer 1

Reset to default 20

Your error doesn't make sense based on the code you're showing, but a common issue with adding PATCH to AngularJS is that it doesn't have a default Content-Type header for that HTTP method (which is application/json;charset=utf-8 for PUT, POST and DELETE). Here's my configuration of the $httpProvider to add patch support:

module.config(['$httpProvider', function($httpProvider) {
    $httpProvider.defaults.headers.patch = {
        'Content-Type': 'application/json;charset=utf-8'
    }
}])
发布评论

评论列表(0)

  1. 暂无评论