提交表单和它的数据到外部URL以及重定向

Submit Form and it's Data to Outside URL as well as redirecting

本文关键字:URL 外部 重定向 数据 表单 提交      更新时间:2023-09-26

我正试图使我的网站前端的登录表单,将采取用户名和密码,并提交到外部URL(为客户的门户)。我希望他们提交给我网站上的表单的数据通过门户传递到新的URL,并尝试登录他们。现在,什么都没发生,我也不知道发生了什么。目前,当我提交表单时,它只是将表单的POST数据附加到我当前的URL,它不尝试将数据发送到外部URL,也不重定向。

HTML:

<form id="redirect-form">
 <p class="mbn"><input type="text" name="loginid" placeholder="username" /></p>
 <p class="mbn"><input type="password" name="password" placeholder="password" /></p>
 <p> <button type="submit" onclick="javascript:register()">Sign In</button></p>
</form>

JS:

function register() {
    form=document.getElementById('redirect-form');
    form.target='_blank';
    form.action='https://pathtomyportal.com';
    form.submit();
}

将表单方法更改为POST

<form id="redirect-form" method="POST">
 <p class="mbn"><input type="text" name="loginid" placeholder="username" /></p>
 <p class="mbn"><input type="password" name="password" placeholder="password" /></p>
 <p> <button type="submit" onclick="javascript:register()">Sign In</button></p>
</form>

你的Javascript是有效的,对我来说工作得很好。向服务器端发送post数据