首页 > 解决方案 > 如何修复已被 api 阻止的 java 脚本中的 cors 策略

问题描述

我正在使用 html 创建登录页面,我的登录 api 是 REST API (django)。运行时显示 cors 策略已被阻止。如何修复此错误?我必须更改一些 java 脚本或 API。

 var username=document.getElementById('UserName').value;
                var password=document.getElementById('Password').value;

            var http = new XMLHttpRequest();
            var url = 'https://creativedsapi.kdns.in/hrapi/login';

            var params={

"username":username,
"password":password
};
                http.open('POST', url, true);

            //Send the proper header information along with the request
            http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            http.setRequestHeader("Content-Type", "application/json");
            http.onreadystatechange = function() {//Call a function when the state changes.
                if(http.readyState === 4 && http.status === 200) {
                alert(http.responseText);

                }
            }
            http.send(JSON.stringify(params));

标签: ajax

解决方案


推荐阅读