我无法使用javascript中的xmlhttprequest进行通话。首先,我从服务器端收到401响应代码。以下是我正在使用的以下代码。
function makeRestCall(){
console.log("Rest call made")
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
alert(this.responseText);
}
};
xhttp.open("POST", "myurk", false, 'username', 'password');
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.send()
alert(xhttp.status);
alert(xhttp.responseText)
我也得到
“请求已被CORS政策阻止”
我能够从邮递员打个电话,并使用基本身份验证并获得响应
我已经引用了各种链接来使用javascript拨打电话。
但是,我仍然无法解决该错误。谁能告诉我我做错了什么。