带有身份验证的Post Ajax:401(未授权)

时间:2019-05-10 09:29:05

标签: javascript ajax authentication post

我正在尝试执行ajax请求,但出现错误401。如果我在浏览器中写了url并将用户名和密码正常工作,则用户名和密码正确。

所有带有xhr.setRequestHeader的注释都经过测试,并返回错误401。

  $.ajax({
type: "POST",
url: url,
data: {'format':'JSON','caller':206,'minDur':8,'maxDur':60},
success: function(data){
  console.log(data)
},
xhrFields: {
    withCredentials: true
},
beforeSend: function (xhr) {
  // xhr.setRequestHeader ("WWW-Authenticate", "Basic " + btoa("****:****"));
  // xhr.setRequestHeader ("WWW-Authenticate", "Basic " + "****:****");
  // xhr.setRequestHeader ("Authorization", "Basic " + "****:****");
  // xhr.setRequestHeader("WWW-Authenticate", 'Basic ' + btoa('****:****'));
  // xhr.setRequestHeader("Access-Control-Allow-Origin", '*');
  // xhr.setRequestHeader("Access-Control-Allow-Origin", 'http://jordidev:5557');
},
crossDomain: true,
username: '****',
password: '****',
dataType: 'json',


error: function (xhr, ajaxOptions, thrownError) {

  // If the connection fails, log the error and return an empty set.
  console.log(xhr);
  console.log(xhr.statusText);
  console.log(xhr.statusCode);
  console.log(xhr.responseText);
  console.log(ajaxOptions);
  console.log(thrownError);

}

0 个答案:

没有答案
相关问题