[英]Not able to send login info request via AJAX call
I am trying to grab the user_ID and password typed by user and sending it to Server. 我试图获取用户键入的user_ID和密码,并将其发送到服务器。 Here's my Javascript code; 这是我的Javascript代码;
<script>
function Display(){
var ID = document.getElementById("user_id").value;
document.getElementById("user_id_D").innerHTML = ID;
var pass = document.getElementById("password_id").value;
var login = "login:" + ID + "-" + pass;
document.getElementById("password_id_D").innerHTML = login;
var request = new XMLHttpRequest();
request.onreadystatechange = function(){
if(this.readyState === 4){
if (this.status === 200) {
if (this.responseText !== null) {
}
}
}
};
request.open("GET",login, true);
request.send(null);
}
</script>
HTML (Bootstrap): HTML(引导程序):
<form class="form col-md-12 center-block">
<input type="text" id="user_id" placeholder="User ID">
<input type="password" id="password_id" placeholder="Password">
<button onclick="Display()">Sign In</button>
</form>
When I write my ID and password and press SignIn button, The browser gives me an error "NS_ERROR_UNKNOWN_PROTOCOL: " at line "request.open("GET",login, true);" 当我输入我的ID和密码并按“登录”按钮时,浏览器在行“ request.open(“ GET”,login,true);“处显示错误” NS_ERROR_UNKNOWN_PROTOCOL:“。 ... What can be the possible reason for that ? ...可能是什么原因?
Please check this code 请检查此代码
request.open("GET",login, true);
The second param is a valid URI . 第二个参数是有效的URI 。 Also you can attach login information via url or data in http POST method. 您也可以通过url或http POST方法中的数据附加登录信息。
I made it work, Actually I was missing the "/" before making login request. 我成功了,实际上我在提出登录请求之前缺少了“ /”。 Now i am sending 现在我正在发送
request.open("GET",login, true);
where my 'login' request is; 我的“登录”请求在哪里;
var login = "/login:" + ID + "-" + pass;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.