配置angularjs模块发送补丁请求 [英] configure angularjs module to send patch request
问题描述
我完全新AngularJs。我试图用发送到Angularjs Django的Tastypie API的补丁请求。我的code是
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");
});
}
}
但是,当我试图发送使用此code的请求我收到一个错误,http.patch不是一个函数。告诉我如何我可以配置NG-应用程序和服务,发送邮件使用AngularJs补丁请求。我读PATCH请求,请在$资源,所以我用$资源也累了吧。但发现同样的结果。请指导我如何配置我从头开始应用发送请求的CRUD,特别PATCH请求
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
推荐答案
您的错误并不能使基础上,code你有显示,但一个共同的问题意识与添加 PATCH
来AngularJS的是,它并没有为HTTP方法默认的Content-Type头(这是应用程序/ JSON的;字符集= UTF-8
对于PUT,POST和DELETE)。下面是我的配置 $ httpProvider
添加补丁支持:
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'
}
}])
这篇关于配置angularjs模块发送补丁请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!