has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
const headers = {
"Accept": "application/json",
"Access-Control-Allow-Origin": "*",
"X-Requested-With": "XMLHttpRequest",
"Access-Control-Allow-Methods" : "GET,POST,PUT,DELETE,OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
}
Axios.post('domen.com/api', dto, config) /* домен фековый */
.then((res)=>console.log('Response',res))
Обычно запрос XMLHttpRequest может делать запрос только в рамках текущего сайта. При попытке использовать другой домен/порт/протокол – браузер выдаёт ошибку.
scope = Flask(__name__, static_url_path='')
# пришлось добавить эту штуку чтобы решить проблему с blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CORS(scope)
var x = []
var y = []
var url ='http://0.0.0.0:8228/scope/store_by_datetime?id_scope_dir=1&datetime_start=2020-10-17%2010:00&datetime_end=2020-10-17%2011:00'
var req = new XMLHttpRequest();
req.overrideMimeType("application/json");
req.open('GET', url, true);
req.onload = function() {
var jsonResponse = JSON.parse(req.responseText);
// do something with jsonResponse
console.log(jsonResponse)
console.log(jsonResponse['result'].length)
for(var k in jsonResponse['result']) {
// console.log(k, jsonResponse['result'][k]);
x.push(jsonResponse['result'][k]['date'])
y.push(jsonResponse['result'][k]['value'])
// console.log(x)
var data = [
{
x: x,
y: y,
type: 'scatter'
}
];
Plotly.newPlot('myDiv', data);
}
};
req.send(null);