jQuery $ .Ajax()不断获得401响应 [英] Jquery $.Ajax() keep getting 401 response
本文介绍了jQuery $ .Ajax()不断获得401响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过API获取JSON,但是它一直在给我
I'm trying to get JSON through an API but it keeps giving me
对预检的响应具有无效的HTTP状态代码401
Response for preflight has invalid HTTP status code 401
这是我的代码
$.ajax({
beforeSend: function (request)
{
request.withCredentials = true;
request.setRequestHeader("Authorization", "Basic" + btoa("usernamehere:keyhere"));
},
crossDomain: true,
contentType: 'application/json',
url: url,
随着用户名和键的不同而不同.我尝试过不使用btoa,尝试使用 headers:
,并且已经编辑了CORS.但是什么都行不通,尽管我可以使用url登录,但是不断地反复抛出相同的错误.
With the username and key different ofcourse.
I've tried without btoa, i've tried using headers:
and I've edited the CORS.
But nothing works, it just keeps throwing the same error over and over eventhough I can login with the credentials if I go to the url.
推荐答案
contentType: 'application/json'
不允许,已修复.
这篇关于jQuery $ .Ajax()不断获得401响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文