如何使用jquery传递用户名和密码
我尝试了几个小时,通过查询传递我的用户名和密码。 我找到了不同的答案,例如
$.ajax({
username: "user",
password: "password",
url: "http://de.wikipedia.org/wiki/S",
type: "GET",
dataType:'json',
success: function() {alert('blub');},
error: function(){alert('nein!');}, });
和
$.ajax({
url: "http://de.wikipedia.org/wiki/S",
success: function() {alert('blub');},
error: function(){alert('nein!');},
beforeSend: function(xhr){
xhr.setRequestHeader("Authorization", "Basic c2Nod1bm5zmRlbGbg0K")},
});
以及
$('#test1').load('http://[email protected]/wiki/S');
更多,但它们都不起作用。 有人可以帮忙吗? 请!!!我绝望了!!!
也许我应该更具体一些。 如果我尝试打开文档,则会收到错误“NetworkError:407 需要代理身份验证 - http://de .wikipedia.org/wiki/S"" 所以我认为用户名和密码传递不正确。
I tried for several hours, to deliver my username and my password with query.
I found different answers like
$.ajax({
username: "user",
password: "password",
url: "http://de.wikipedia.org/wiki/S",
type: "GET",
dataType:'json',
success: function() {alert('blub');},
error: function(){alert('nein!');}, });
and
$.ajax({
url: "http://de.wikipedia.org/wiki/S",
success: function() {alert('blub');},
error: function(){alert('nein!');},
beforeSend: function(xhr){
xhr.setRequestHeader("Authorization", "Basic c2Nod1bm5zmRlbGbg0K")},
});
and
$('#test1').load('http://[email protected]/wiki/S');
and several more, but neither of them is working.
Can anybody help?
Please!!! I´m despaired!!!
Maybe I should be more specific.
If I try to open the document I get the Error ""NetworkError: 407 Proxy Authentication Required - http://de.wikipedia.org/wiki/S""
So I think the username and password isn´t delivered right.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您似乎违反了同源政策:
Looks like you have a violation of the same origin policy:
为了避免 @jk 提到的 SOP,您可能需要一个服务器端脚本(在您的主机上)来加载外部 url 并将数据返回到您的客户端脚本。
编辑:添加您的评论。
我是一个 .Net 人员,所以我的 PHP 帮助将是有限的。我认为您可以使用 CURL 在 PHP 中使用外部 Web 资源,并且我假设 CURL 可以在帖子中传递凭据。您的 javascript 必须发布到您的 PHP 文件,该文件将发布到 wikipedia 并返回您需要的任何内容给 javascript。
to avoid the SOP that @jk mentioned you would likely need a server side script (on your host) to load the external url and return the data to your client side script.
Edit: to add re your comment.
I'm a .Net guy so my PHP help will be limited. I think you can use CURL to consume external web resources in PHP and I'm assuming that CURL can pass in credentials on a post. Your javascript would have to post to your PHP file, which would post to wikipedia and return whatever you needed to the javascript.
尽管我建议您对密码非常小心,并且不要将其存储在可公开访问的 (html/js) 文件中,但我对此有 10 美分的意见。
对于这个维基百科站点,登录是这样发生的:
进行 POST 事务:
发送以下参数:
希望这能让您继续下去。
Although I advice you to be very careful with your password, and not to store it inside a publicly accessible (html/js) file, here's my 10 cents on this.
For this Wikipedia site, a login happens like this:
A POST transaction is made to:
The following parameters are sent:
Hope that will get you going.