我已经阅读了很多关于CORS和身份验证的文档,我非常确定能够正确地完成任务。我正在尝试验证jQuery.ajax GET CORS请求,如下所示:
$.ajax('http://httpbin.org/basic-auth/foo/bar', {
type: 'GET',
username: 'foo',
password: 'bar',
xhrFields: {
withCredentials: true
}
}).then(function (data) {
alert('success');
}, function (xhr) {
alert('failure');
});
但浏览器不断提示我输入凭据,而不是发送提供的凭据。请在http://jsfiddle.net/BpYc3/处尝试此操作,其中http://httpbin.org应该发送正确的CORS标头。