Javascript 如何将GET响应数据传递给POST请求

Javascript 如何将GET响应数据传递给POST请求,javascript,angularjs,Javascript,Angularjs,我刚刚使用Angularjs,在解析JSON响应时遇到了问题。我正在为登录页面进行客户端身份验证,我使用getrequest从服务器端获取数据,并为客户端发出post请求。 HTML代码: <form ng-submit="loginform(logcred)" class="ng-scope ng-pristine ng-valid center" name="logform"><br/><br> <tr ng-repeat="logcred

我刚刚使用Angularjs,在解析JSON响应时遇到了问题。我正在为登录页面进行客户端身份验证,我使用
get
request从服务器端获取数据,并为客户端发出
post
请求。 HTML代码:

    <form ng-submit="loginform(logcred)" class="ng-scope ng-pristine ng-valid center" name="logform"><br/><br>
<tr ng-repeat="logcred in serverinfo"></tr>
<div>
  <label form="emailinput"><b>Email</b></label>
  <input type="email" class="form-control" name="uname" id="emailinput" placeholder="you@example.com" ng-model="logcred.username" >
</div>

<div>
  <label form="pwdinput"><b>Password</b></label>
  <input type="password" class="form-control" name="pwd" id="pwdinput" placeholder="*******" ng-model="logcred.password">
</div>

<div>
    <button type="cancel" class="btn" ng-click="toggle_cancel()">Cancel</button>
    <button class="btn btn-primary" ng-click="submit()">Login</button>
</div>
<br/>   
</form>
我面临的问题是,我需要将
GET
响应数据发送到
POST
请求中,然后我在那里进行条件检查,如果用户名和密码匹配,则应该给出成功消息。但我不确定我的想法是否正确

我做错了什么


任何帮助/建议都将不胜感激。

您可以尝试下面的代码

$scope.loginform = function(serverinfo,username,password){
  $http({
        url: 'http://localhost:3000/loginfo',
        method: 'POST',
        data: {
            "username" :username,
            "password" :password,
            }
        })
        .then(
        function successCallback(response){
        console.log(response);
        if (response) {  // Response will be either true or false. For this yu need to change the API response.
            //Logged in successfully
        }else{
           //Something went wrong
        }
    });
}

您可以尝试下面的代码

$scope.loginform = function(serverinfo,username,password){
  $http({
        url: 'http://localhost:3000/loginfo',
        method: 'POST',
        data: {
            "username" :username,
            "password" :password,
            }
        })
        .then(
        function successCallback(response){
        console.log(response);
        if (response) {  // Response will be either true or false. For this yu need to change the API response.
            //Logged in successfully
        }else{
           //Something went wrong
        }
    });
}

在服务器端检查用户名和密码,若匹配发送成功消息,则不需要发送get请求即可it@ThanhTùng。我创建了plunker:我不知道如何进行服务器端检查,你能修改我的plunker吗?或者,如果你有任何工作示例,请将我@ThanhTùng删除为什么你需要获取请求来获取用户名和密码?你们不需要它,只需在服务器中发布数据,签入数据库,若匹配,发送成功消息给用户实际上我并没有使用数据库。我使用了
JSON
server。这就是为什么我认为在服务器端你检查用户名和密码,如果匹配发送成功消息,你不需要发送get请求it@ThanhTùng。我创建了plunker:我不知道如何进行服务器端检查,你能修改我的plunker吗?或者,如果你有任何工作示例,请将我@ThanhTùng删除为什么你需要获取请求来获取用户名和密码?你们不需要它,只需在服务器中发布数据,签入数据库,若匹配,发送成功消息给用户实际上我并没有使用数据库。我使用了
JSON
server。这就是为什么我在想是的。我会试试的。我要试试@rakesh