javascript - 在 chrome 开发工具的“响应”选项卡中有可用数据时,在 AJAX 响应中获取“未定义”
问题描述
我正在尝试从以下跨域 ajax 请求中获取响应,但未成功定义:
$.ajax({
type: "GET",
url: "https://path_to_app/rest/jjwt",
crossDomain: true,
dataType: 'script',
contentType: 'text/plain;charset=UTF-8',
beforeSend: function(xhr) {
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
},
success: function (response, textStatus, xhr) {
console.log(response);
console.log(textStatus);
},
error: function (jqXHR, exception) {
var msg = '';
if (jqXHR.status === 0) {
msg = 'Not connect.\n Verify Network.';
} else if (jqXHR.status == 404) {
msg = 'Requested page not found. [404]';
} else if (jqXHR.status == 500) {
msg = 'Internal Server Error [500].';
} else if (exception === 'parsererror') {
msg = 'Requested JSON parse failed.';
} else if (exception === 'timeout') {
msg = 'Time out error.';
} else if (exception === 'abort') {
msg = 'Ajax request aborted.';
} else {
msg = 'Uncaught Error.\n' + jqXHR.responseText;
}
console.log(msg);
}
});
解决方案
推荐阅读
- search - 使用 ML.NET 进行复杂搜索
- blender - 从 Blender 导出模型到 .OBJ 后,某些面孔未显示
- c# - 如何使用 Unity Web 请求下载多个文件?
- unity3d - 保护 Unity3d .apk 文件 (Oculus)
- user-interface - Flutter,按下按钮后如何复制文本?
- python - 我如何在 python 应用程序上部署 heroku 调度程序
- reactjs - 如何在 React 中使用 onClick 将值从一个组件传递到另一个组件
- jhipster - 在 JHipster JDL 中使用 Vuejs 蓝图
- python - 比较列表python中的每个元素
- python - 单元测试 apache 梁作业