gpt4 book ai didi

javascript - IE 中的 HTAccess 使用 javascript 或 jquery

转载 作者:行者123 更新时间:2023-11-29 15:01:44 25 4
gpt4 key购买 nike

我需要调用 xyx.com 等网站的 rest api。

它有一个通常的身份验证,我已经在 jquery 中实现了它。

return $.getJSON('xyx.com/restapi/login?userid=aaa&pass=qqq'+"&xslt=json.xsl&
callback=?",function(jsonResult)
{
if(jsonResult.response.status == 'success')
{
...
...
}
},"jsonp");

上面的工作正常。

现对上述站点xyx.com提供HT Access

我把上面getJSON中使用的URL替换成如下

http://msf:sks1l*@xyx.com/restapi/login?userid=aaa&pass=qqq

其中 msf 和 sks11* 是 HT 访问凭据。

上面的代码在 FF 中运行良好,但在 IE 中运行不正常。

任何可能的解决方案或变通方法。

最佳答案

$.getJSON() 只是一种特定类型的 $.ajax() 调用的简写。 jQuery 文档显示了详细信息:http://api.jquery.com/jQuery.getJSON/ . $.getJSON 等同于:

$.ajax({
url: url,
dataType: 'json',
data: data,
success: callback
});

并查看位于 http://api.jquery.com/jQuery.ajax/$.ajax() 文档它说:

If the server performs HTTP authentication before providing a response, the user name and password pair can be sent via the username and password options.

因此只需使用 $.ajax() 表单并传递用户名和密码,如下所示:

$.ajax({
url: "http://xyx.com/restapi/login?userid=aaa&pass=qqq",
dataType: 'json',
success: function(jsonResult) {
/* your success code */
},
username: 'msf',
password: ':sks1l*@'
});

关于javascript - IE 中的 HTAccess 使用 javascript 或 jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9063454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com