我已经做了一个简单的表格来获取用户输入的密码和url参数的内容,然后我将其作为发布请求发送到我在我的网站上拥有的端点,该端点将接收所有信息并重新设置用户密码。这是html代码:
<!DOCTYPE html>
<html>
<body>
<input type="text" name="password" id="pass" placeholder="Enter password"><br>
<button onclick="send()">Click me</button>
<script>
function send() {
var password = document.getElementById("pass");
var actionCode = GetURLParameter('oobCode');
var apiKey = GetURLParameter('apiKey');
var lang = GetURLParameter('lang');
var params = {
"password":pass,
"actionCode":actionCode,
"apiKey":apiKey,
"lang":lang
}
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://www.website.com/auth/resetpassword", true);
xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
xhr.send(JSON.stringify(params));
window.location = xhr.responseText;
}
function GetURLParameter(sParam){
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return sParameterName[1];
}
}
}
</script>
</body>
</html>
当我单击上面定义的按钮时,我的浏览器转到加载页面,然后在一秒钟内全部停止,我不得不在chrome上记录我的控制台,因为错误显示出来,然后消失了很多快速: