我正试图从以下跨域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);
}
});