解决ajax跨域问题from origin ‘null‘ has been blocked by CORS policy

问题:运行ajax会报以下错误
在这里插入图片描述
解决ajax跨域问题from origin ‘null‘ has been blocked by CORS policy_第1张图片

解决方式一共有三种:

  1. 下载一个webstorm完事
  2. 如果是vscode,在扩展中有个插件叫做live server,安装上这个插件之后在代码界面右键或者使用快捷键alt+L+O来运行代码,即可将代码成功运行
    解决ajax跨域问题from origin ‘null‘ has been blocked by CORS policy_第2张图片
    解决ajax跨域问题from origin ‘null‘ has been blocked by CORS policy_第3张图片
  3. 有一个软件叫做phpstudy,官方网站:https://www.xp.cn/download.html

具体实现步骤:

  1. 下载安装
  2. 点配置
    解决ajax跨域问题from origin ‘null‘ has been blocked by CORS policy_第4张图片
  3. 选择一个路径,这个路径最好是你需要服务器的那个文件夹
    解决ajax跨域问题from origin ‘null‘ has been blocked by CORS policy_第5张图片
  4. 切换到网站界面,点击创建网站
    解决ajax跨域问题from origin ‘null‘ has been blocked by CORS policy_第6张图片
  5. 这里只用输入域名即可,建议最好是英文,在输入域名后会在本地出现相应的文件夹
    解决ajax跨域问题from origin ‘null‘ has been blocked by CORS policy_第7张图片
    解决ajax跨域问题from origin ‘null‘ has been blocked by CORS policy_第8张图片
  6. 将你需要服务器的代码全部ctrl+c/v进去
    解决ajax跨域问题from origin ‘null‘ has been blocked by CORS policy_第9张图片
  7. 在软件页面启动服务器,在浏览器中删除所选中的
    在这里插入图片描述
    解决ajax跨域问题from origin ‘null‘ has been blocked by CORS policy_第10张图片
    解决ajax跨域问题from origin ‘null‘ has been blocked by CORS policy_第11张图片
  8. 成功
  9. 解决ajax跨域问题from origin ‘null‘ has been blocked by CORS policy_第12张图片

你可能感兴趣的:(ajax,ajax跨域问题,vscode,javascript)