Html 对本地服务器的HTTP get请求

Html 对本地服务器的HTTP get请求,html,get,httprequest,Html,Get,Httprequest,我正在尝试将身份验证数据发送到本地服务器 此url应返回json数据。 实际上我有一个错误: 您正试图以用户“%5Bobject%20Object%5D”身份向网站本地主机进行身份验证 <form method="get" onsubmit="javascript:document.location='https://' + $('login') + ':' + $('pass') + '@localhost:5004/logs';"> <input type="text" n

我正在尝试将身份验证数据发送到本地服务器 此url应返回json数据。 实际上我有一个错误: 您正试图以用户“%5Bobject%20Object%5D”身份向网站本地主机进行身份验证

<form method="get" onsubmit="javascript:document.location='https://' + $('login') + ':' + $('pass') + '@localhost:5004/logs';">
<input type="text" name="login" id="login" />
<input type="password" name="pass" id="pass" />
<input type="submit" value="ok"/>
</form>
相同的401错误

onsubmit-even-handler属性直接接受JavaScript,您不需要在JavaScript前面加前缀:


“登录”是什么意思?这不是有效的JavScript。从这里可以看出,那个人正在使用Perl,你也是吗?我想我需要结束这个问题。那个人也在使用jQuery。你的情况完全不同。很明显,您不能像那样使用任何代码。这就像在C中放置C++代码一样
function add(login,pass) {
var str = login+':'+pass;
var http = new XMLHttpRequest();
var url = "https://localhost:5004/logs";
http.open("GET", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
    alert(http.responseText);
    }
}
http.send(str);
}
<form method="get" onsubmit="document.location='https://' + $('login') + ':' + $('pass') + '@localhost:5004/logs';">
    <input type="text" name="login" id="login" />
    <input type="password" name="pass" id="pass" />
    <input type="submit" value="ok"/>
</form>