<keygen> 提交表单后,POST 中的元素为空



我有一个如下形式:

<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元素总是空的?我做错什么了吗?

感谢您的回答,提前谢谢。

已解决!

因此,出于某种原因,准备一个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();     
};

最新更新