如何使用具有基本身份验证的JQuery进行JSONP调用? [英] How do I make a JSONP call with JQuery with Basic Authentication?
问题描述
使用JQuery,我该如何调用需要基本身份验证的JSONP API?
我可以通过编程方式处理此问题,还是用户必须进行交互,然后在登录对话框中输入用户名和密码?
JSONP请求不使用XMLHttpRequest对象/系统.因此,无法直接执行此操作.
我尝试了几次FinnNk答案中提到的方法,但在阅读在jQuery邮件列表上的="noreferrer">此讨论.
更新
当我说没有办法直接做到这一点"时,我的意思是:
- 您无法以编程方式设置HTTP身份验证凭据(但是,我测试过的大多数浏览器都会提示用户输入凭据)
- 如果您不希望用户手动输入凭据,则需要使用服务器代理您的请求.有关出色的说明和示例,请参见此博客文章.
Using JQuery, how would I call a JSONP API that required basic authentication?
Can I programatically handle this, or does the user have to interact and enter the username and password into the logon dialog?
The JSONP request does not use the XMLHttpRequest Object / System. Hence there is no way to do this directly.
I tried several times the approach mentioned in FinnNk's answer, but finally gave up after reading this discussion on the JQuery mailing list.
Update
When I said "no way to do this directly", what I meant is:
- You can't programmatically set the HTTP auth credentials (However, most browsers I have tested will prompt the user for credentials)
- If you don't want the user to enter the credentials manually, you need to use a server to proxy your request. See this blog post for an excellent description and example.
这篇关于如何使用具有基本身份验证的JQuery进行JSONP调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!