0

我有一个如下表格:

<form name="signupForm" id="signupForm" method="POST" ng-submit="create()">
            <input type="hidden" name="username" id="username" value="mtest">
            <input type="text" placeholder="Account name" name="webid" ng-model="account.webid" ng-focus="isFocused" ng-blur="isFocused = false"><br>
            <input type="text" placeholder="Full name" name="name" ng-model="account.name"><br>
            <input type="text" placeholder="Email" name="email" ng-model="email"><br>
            <input type="text" placeholder="Picture URL" name="pictureURL" ng-model="account.pictureURL"><br>
            <keygen id="spkac" name="spkac" challenge="randomchars" keytype="rsa" form="signupForm" hidden>
            <br>
            <input type="submit" id="submit" value="Submit">
</form>

数据按如下方式传递给 POST:

$http({
          method: 'POST', 
          url: uri,
          data: $("#signupForm").serialize(),
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Accept': 'application/x-x509-user-cert'
          },
          withCredentials: true
        }).

一旦我提交表单以使用 POST http 请求发送它,我会得到$("#signupForm").serialize()如下信息:

"username=mtest&webid=mtest.databox.me%2Fprofile%2Fcard%23me&name=M+Test&email=mtest%40test.com&pictureURL=picURL&spkac="

为什么keygen元素总是空的?我做错了什么吗?

任何答案表示赞赏,在此先感谢。

4

1 回答 1

0

解决了!

因此,出于某种原因,准备一个 HTTP 请求来做这件事是行不通的。相反,需要设置表单操作并立即提交表单,以便与它一起发送注册机。这里的解决方案:

模板中,动作是参数化的:

    <form name="signupForm" id="signupForm" method="POST" action="{{actionUrl}}">
     ...
    <input type="submit" id="btnSubmit" value="Submit" ng-click="completeForm()">

控制器设置动作并提交表单如下:

$scope.completeForm = function () {
        $scope.actionUrl = "https://" + document.getElementById("username").value + "...";
        document.getElementById("signupForm").submit();     
};
于 2015-12-10T10:23:23.970 回答