angularjs ajax header,AngularJS $resource Headers POST

这篇博客探讨了在AngularJS中使用资源服务($resource)如何处理HTTP头信息。作者提出了四个问题:如何在调用时而非在工厂方法中指定头信息?为什么在更新方法中设置的头信息会默认应用?如何为整个工厂设置通用的HTTP头信息?以及参数传递中的'@'符号含义和参数匹配规则。内容涉及AngularJS服务配置和HTTP请求的细节。
摘要由CSDN通过智能技术生成

I would like to know how to pass headers to AngularJS $resource method

Here is the factory method

.factory('DataRepository', function ($resource) {

return $resource(serviceUrlPrefix + '/api/v1/AppList/:id', { id: '@id' }, { 'query': { method: 'GET', isArray: false }, 'update': { method: 'PUT', AppList: '@req', headers: { 'X-Requested-With': 'XmlHttpRequest' } } });

});

Here is the call to the dataRepository

dataRepository.update({ id: req[uniqueIDColumn] }, req, function (data) {

},

function (error) {

});

This code works fine. But i have few queries

Question 1:

Rather than specifying the headers in the factory method , how can i specify it in the call to the factory method? I tried few methods but it didnt work out.

Question 2:

I specified the header in the update method in the factory. When i perform "Save" using that factory, that header has been taken by default. But i have specified it explicitly for PUT method. Right? Why and how?

Question 3:

If i would like to specify the header for the particular factory in common for all Http methods, what is the way to do it?

Question 4:

What is the nomenclature for passing the parameters and the significance of "@" symbol before parameter and also in the below part, AppList is the parameter name used in the WebAPI, is it mandatory that it should match the parameter name in the WebAPI method, if its not matching, its not working:(

AppList: '@req'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值