【问题标题】:AngularJS how to make a POST JSONAngularJS如何制作一个POST JSON
【发布时间】:2013-11-24 20:55:35
【问题描述】:

我正在尝试发帖,但下面似乎不起作用它没有发布但console.log() 看起来像一个放置请求,即

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

工厂

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

控制器

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

我做错了什么?

【问题讨论】:

    标签: javascript angularjs restangular


    【解决方案1】:

    根据文档 (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);
    

    请注意,帖子只有一个输入

    您可以将 'api/v1' 添加到您的基址 - 无需随身携带 (https://github.com/mgonto/restangular#setbaseurl)

    我还建议对资源路径使用复数形式,但这是一些人不遵循的惯例 - 我想这是一个品味问题

    【讨论】:

      猜你喜欢
      • 2015-06-29
      • 2021-08-31
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多