前端项目 index.html 中发请求 fetch

想要在前端项目 index.html文件中向后端发起请求,但是引入axios报错(我这边会报错),可以使用fetch

javascript 复制代码
//window.location.origin----获取域名,包括协议、主机号、端口号
      fetch(window.location.origin + "/api/plant-consumer/plant/getGeoInfoByOutNetIp?outerNetIp=", {
        method: "GET", // 请求方法
        withCredentials: false, //是否开启跨域,开启后可以设置自定义的header头,但是后端要开启*以及允许哪些header头
        headers: { // 填写headers请求头
          "Content-Type": "application/x-www-form-urlencoded",
          Authorization: localStorage.getItem("Authorization"),
        },
      })
        .then(resp => resp.json())
        .then(res => {
        
        })
        .catch(() => {
        })
相关推荐
前端 贾公子14 分钟前
uni-app工程化实战:基于vue-i18n和i18n-ally的国际化方案 (下)
前端
@zulnger22 分钟前
selenium 操作浏览器
前端·javascript·selenium
xiaofeichaichai33 分钟前
Symbol 与 Iterator / Generator
前端·javascript
维双云39 分钟前
小程序店铺装修模板怎么选?从首页布局、商品展示到下单路径这样看更实际
前端·小程序
YHL1 小时前
📖前端 HTTP 请求 & LLM 接口开发
前端·https
西部荒野子1 小时前
4.JS Bundle 执行流程
前端
假如让我当三天老蒯1 小时前
State和Props区别和左右(自学用)
前端·react.js
西部荒野子1 小时前
1. 建立源码地图
前端
西部荒野子1 小时前
3.RCTRootView 加载 Bundle 流程
前端
西部荒野子1 小时前
2.iOS 启动到 RCTRootView
前端