Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何通过按钮登录(用户:pass)发送GET请求?_Html_Ajax_Login_Passwords_Get - Fatal编程技术网

Html 如何通过按钮登录(用户:pass)发送GET请求?

Html 如何通过按钮登录(用户:pass)发送GET请求?,html,ajax,login,passwords,get,Html,Ajax,Login,Passwords,Get,我想要一个网页上的按钮,当按下时,它的作用相当于在浏览器中输入此url并按enter键 下面的代码为我提供了按钮,但它似乎不想传递凭据,firebug说: 拒绝访问受限URI“代码:”1012 如果我删除凭据,它会显示401未经授权 提前谢谢 <html> <head> <script type="text/javascript"> function simpleAjax() { var xmlhttp; if (window.XMLHttpRequest)

我想要一个网页上的按钮,当按下时,它的作用相当于在浏览器中输入此url并按enter键

下面的代码为我提供了按钮,但它似乎不想传递凭据,firebug说:

拒绝访问受限URI“代码:”1012

如果我删除凭据,它会显示401未经授权

提前谢谢

<html>
<head>
<script type="text/javascript">
function simpleAjax()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("Divku").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","http://user:pass@www.example.com/example/button_24",true);
xmlhttp.send();
}
</script>
</head>
<body>

<h2>AJAX</h2>
<button type="button" onclick="simpleAjax()">Request data</button>
<div id="Divku"></div>

</body>
</html>

函数simpleAjax()
{
var-xmlhttp;
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“Divku”).innerHTML=xmlhttp.responseText;
}
}
open(“GET”http://user:pass@www.example.com/example/button_24”,真实);
xmlhttp.send();
}
AJAX
请求数据
新代码

<head> <meta http-equiv="refresh" content="30" >  </head>
<img alt="screenshot" src="http://a:a@www.example.com/example/screenshot.jpg">
<head>
<script type="text/javascript">
function simpleAjax()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("Divku").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.setRequestHeader('Authorization','Basic YTph');
xmlhttp.open("GET","http://www.example.com/example/button_24",true);
xmlhttp.send();
}
</script>
</head>
<body>
<br>
<button type="button" onclick="simpleAjax()">Volume Up</button>
<div id="Divku"></div>

</body>

函数simpleAjax()
{
var-xmlhttp;
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“Divku”).innerHTML=xmlhttp.responseText;
}
}
setRequestHeader('Authorization','Basic YTph');
open(“GET”http://www.example.com/example/button_24“,对);
xmlhttp.send();
}

增大音量
我认为您需要
在AJAX对象上设置requestheader
,并提供身份验证头,而不是将其传递到URL中。请记住,服务器正在查找标头

Authorization: Basic abc123==
(或传真)

也许可以检查一下提供AJAX请求的凭据


还有,MDN是关于方法的。

谢谢,但我是个真正的业余爱好者。我从谷歌搜索中找到的关于如何制作按钮的网页上复制了所有这些代码。我甚至不知道什么是ajax。不幸的是,关于提供凭据的链接对我来说毫无意义。基本上,在调用
xmlhttp.open
之前,您需要类似
xmlhttp.setRequestHeader('Authorization','Basic abc123=')
其中
abc123==
是用户名的base-64编码版本,一个冒号(
),然后是密码组合。因此有一些翻译将user:pass转换为字符串,我将“abc123==”替换为?Ok,所以我得到了user:pass的翻译,它是a:a。现在,我的代码看起来是这样的,它会抛出此错误未捕获异常:[异常…”组件返回的故障代码:0x80004005(NS_错误\u失败)[nsimlHttpRequest.setRequestHeader]“nsresult:”0x80004005(NS_错误\u失败)”位置:“JS帧::file:///C:/Documents%20and%20Settings/User/Desktop/webkeyautoref.html ::simpleAjax::第23行“数据:否]@max:您的用户名和密码是否已编码?或者您只是将
基本a:a
传递给setRequestHeader方法?