2016-10-21 5 views
1

私はまだAngularを少し新しくしていますが、私はAPIバックエンド(私はフロントエンドを構築しています)を通じてログイン後のリクエストを送信しようとしています。Angularログインリクエストに-dを追加する

ので、APIのドキュメントでは、このようなものです:

カール "URL" -d'user [メール]は、いくつかの%40email.com &ユーザー[パスワード] =パスワード&ユーザー[password_confirmation] =パスワードを」= - X POST \ -H "同意する:アプリケーション/何か" \ -H "のContent-Type:アプリケーション/ x-www-form-urlencodedで"

これは私のフォームです:

<form ng-submit='submit()' class='login-form'> 
     <a ng-href='#/signup'><span class='md-text'>Signup</span></a> 
     <span class='md-text'>|</span> 
     <a><span class='md-text'>Forgotten password?</span></a> 
     <input class='login-input' type='text' ng-model='username' placeholder='&#61447; Username'> 
     <input class='login-input' type='password' ng-model='password' placeholder='&#xf023; Password'> 
     <button type="submit" class="btn btn-primary btn-login" ng-model='submit'>Login</button> 
    </form> 

そして、これ私の同僚の一員ですntroller:

$scope.submit=function() { 
    console.log('Submit'); 

    var reqLogin = { 
    method: 'POST', 
    url: 'URL', 
    headers: { 
     'Accept': 'application/blah, 
     'Content-Type': 'application/x-www-form-urlencoded' 
    } 
    } 

    $http(reqLogin).success(function(response) { 
    console.log(response); 
    }); 
} 

これはばかげた質問かもしれませんが、私は角にヘッダを追加するために知って、私は上記の持っているJSONオブジェクトで行います。

HTTPリクエストに-d部分を追加するにはどうすればよいですか?

答えて

-1

私は、jQueryを混合する際にパラメータを配置することができました。

 var reqLogin = { 
     method: 'POST', 
     url: 'URL', 
    data: $.params({ 
"user[email]": email, 
"user[password]": password 
)}, 
     headers: { 
      'Accept': 'application/blah, 
      'Content-Type': 'application/x-www-form-urlencoded' 
     } 
     } 
関連する問題