【发布时间】:2019-06-17 07:52:23
【问题描述】:
我正在尝试使用引导程序创建一个登录页面,在单击按钮时,将通过“POST”对 API 进行 ajax 调用,这应该将 OTP 发送到我的手机。
我在 apache localhost 上运行它。在检查源时,我收到错误
HTTP400: BAD REQUEST - The request could not be processed by the server due to invalid syntax.
(XHR)POST - https://<api>
我没有收到任何一次性密码
我已经在 Postman 上测试过 API 并且它们可以工作。我尝试使用语法,但没有任何效果。
<!--body>
<form class="login100-form validate-form p-l-55 p-r-55 p-t-178" action="/Login_v8/otp.html">
<span class="login100-form-title">Sign In</span>
<div class="wrap-input100 validate-input m-b-16" data-validate="Please enter phone number">
<input class="input100" type="phone" name="Ph" placeholder="Phone number" id="Ph">
<span class="focus-input100"></span>
</div>
<div class="text-right p-t-13 p-b-23">
<span class="txt1">Forgot</span>
<a href="#" class="txt2">Username / Password?</a>
</div>
<div class="container-login100-form-btn">
<button class="login100-form-btn" onclick="generate_otp()">Sign in</button>
</div>
<!-- other lines of code>
</form>
<!--other lines of code>
<script>
function generate_otp(){
var request = new XMLHttpRequest();
var Ph = document.getElementById('Ph');
var arr = {Ph: "968*******",
device:{
deviceId: "1234"
platform: "1",
appType: "0"
}
};
let json = JSON.stringify(arr);
request.open("POST","<api>", false);
request.setRequestHeader('Content-type','application/json');
request.send(JSON.stringify(arr));
}
</script>
它应该向我的手机发送 OTP。
【问题讨论】:
标签: javascript ajax api