8
HTTPサービスを使用するには、サーバーに接続する必要があります。http基本認証をAjaxコールで使用する
https://example.com/service
を使用して、ブラウザでサービスを開始しようとしていますが、基本的な認証ダイアログが表示されます。
URLをhttps://username:[email protected]/service
に変更すると簡単に回避されます。
Ajaxは常にかかわらず401 Unauthorized
になり使用して同じことをやろうとしている:私は、同様のシナリオで自分を苦労
$.ajax({
url: 'https://username:[email protected]/service',
// rest repeats
type: "GET",
async: true,
success: function(text) { alert('success'); },
error: function (text) { alert('error') },
complete: function(text) { alert('complete'); }
});
$.ajax({
url: 'https://example.com/service',
username: username,
password: password,
// snip repeat
});
$.ajax({
url: 'https://example.com/service',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic "
+ btoa(username + ":" + password));
},
// snip repeat
});
http://stackoverflow.com/a/11960692/1730482をご覧ください。 – marklap
@marklap私はalredyがその質問をチェックしましたが、まだ401エラーがあります – Ste
私はリンク先のソリューションを試しましたか?そのソリューションの第2ブロックは具体的には? – marklap