我尝试使用JS对象作为有效负载在/ login url上发出POST请求,下面是代码。 问题是我有两个网络电话,第一个是'OPTIONS',第二个是POST。
我不想要进行OPTIONS调用,我只想要POST调用。
感谢您的帮助!
var loginData = Restangular.one('login');
loginData.username = 'username@email.com';
loginData.password = 'password';
return loginData.post().then(function(user) {
console.log(user.username, user.email);
});
答案 0 :(得分:1)
问题出在函数addFullRequestInterceptor中,我没有返回元素数据。
Restangular.addFullRequestInterceptor(function(element, operation, what, url, headers, params, httpConfig) {
//some logic here...
//originally, the return below was not there... It is mandatory, if nothing is returned in that function, any POST or PUT request won't have any payload data.
return {
element: element,
headers: headers,
params: params,
httpConfig: httpConfig
};
});