简体   繁体   English

AngularJS如何制作POST JSON

[英]AngularJS how to make a POST JSON

I'm trying to make a post but below does not appear to work it does not post but console.log() looks like a put request ie 我正在尝试发帖但是下面似乎不起作用它不发布但是console.log()看起来像一个put请求即

http://127.0.0.1/api/v1/participant?account=%7B%22pk%22:1%7D&email=someemail@gmail.com

factory

app.factory('CbgenRestangular', function(Restangular) {
    return Restangular.withConfig(function(RestangularConfigurer) {
        RestangularConfigurer.setBaseUrl('http://127.0.0.1');
    });
});

controller 调节器

$scope.participant = {email :$scope.email, password: "", account:{pk:1}};
CbgenRestangular.all('api/v1/participant').post("participant", $scope.participant);

What I'm I doing wrong? 我做错了什么?

according to the documentation ( https://github.com/mgonto/restangular#lets-code ): 根据文档( https://github.com/mgonto/restangular#lets-code ):

// First way of creating a Restangular object. Just saying the base URL 
var baseAccounts = Restangular.all('accounts');

var newAccount = {name: "Gonto's account"};

// POST /accounts 
baseAccounts.post(newAccount);

note that post has a single input 请注意,帖子只有一个输入

you can add 'api/v1' to your base address - there's no need to carry it around ( https://github.com/mgonto/restangular#setbaseurl ) 你可以在你的基地址添加'api / v1' - 没有必要随身携带它( https://github.com/mgonto/restangular#setbaseurl

I would also suggest using the plural form for a resource route, but that's a convention that some people don't follow - I guess it is a matter of taste 我还建议使用复数形式的资源路线,但这是一个有些人不遵循的惯例 - 我想这是一个品味的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM