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://c2odWhbm5zmlbGpgOK@de.wikipedia.org/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.
Looks like you have a violation of the same origin policy:
Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol. Script and JSONP requests are not subject to the same origin policy restrictions.
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.
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:
http://de.wikipedia.org/w/index.php?title=Spezial:Anmelden&action=submitlogin&type=login&returnto=S
The following parameters are sent:
- wpName:blablabla
- wpPassword:blablabla
- wpCentralLogin:1
- wpLoginAttempt:Anmelden
- wpLoginToken:bignumberthingythatwillprobablybedifferenteachtime
Hope that will get you going.
精彩评论