如何使用axios CDN和axios.get

时间:2020-02-05 23:41:23

标签: javascript axios

此代码无效!我需要在页面中使用axios,但CORS策略已阻止从原点“ https://google.com/”访问“ http://easysaham.ir”处的XMLHttpRequest:在“”中没有“ Access-Control-Allow-Origin”标头请求的资源。

<?php header('Access-Control-Allow-Origin: *'); ?>

<!DOCTYPE html>
<html>
<head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>Title</title>
</head>
<body>

<script src='https://unpkg.com/axios/dist/axios.min.js'></script>

<script>
axios.get('https://google.com/').then(response => {
    console.log(response.data);
});
</script>
</body>
</html>

0 个答案:

没有答案