Rails形式のルーティングに対する$httpのPOSTでパラメータを渡せない

47 views
Skip to first unread message

Pon Iso

unread,
Jun 2, 2017, 9:45:51 AM6/2/17
to Angular Japan User Group
こんにちは。

$httpのPOSTでAPサーバにパラメータをわたしたいのですが、、、

$scope.onclick =function(){
    alert( "test" );
    $http({
        method: 'POST',
        url: '/oauth',
        params: { domain: $scope.domain }
    });
};

上記コードてすとPOSTメソッドでもURLは
/oauth?domain=値
となってしまいます。

期待しているのは、アクセス先は/oauthで
データとしてdomain=値を渡したいのですが、、、。

お知恵を拝借願えますでしょうか?

norami...@gmail.com

unread,
Jun 2, 2017, 9:51:50 AM6/2/17
to Angular Japan User Group
Pon Iso 様

以下の通り、paramsじゃなくてdataにすれば解決するのではないかと思います。


params – {Object.<string|Object>} – Map of strings or objects which
will be serialized with the paramSerializer and appended as GET parameters.
data – {string|Object} – Data to be sent as the request message data.

https://docs.angularjs.org/api/ng/service/$http


norami


2017年6月2日金曜日 22時45分51秒 UTC+9 Pon Iso:

Pon Iso

unread,
Jun 7, 2017, 9:15:10 PM6/7/17
to Angular Japan User Group
 noramiさん、お返事ありがとうございます。
data 属性をセットすると無事POSTすることができました。
ありがとうございました。

Reply all
Reply to author
Forward
0 new messages