MockAPI中使用put修改数据报错400

put修改数据报错400

错误写法

`axios.put('https://5f4c5373ea007b0016b1df40.mockapi.io/room/room?id=' + id, jsContent).then(
     function (post) {
         window.location.reload();
     })

报错400

正确写法

`axios.put('https://5f4c5373ea007b0016b1df40.mockapi.io/room/room/' + id, jsContent).then(
    function (post) {
        window.location.reload();
    })

控制台不报错

原因分析

虽然在浏览器中直接输入IP地址: https://5f4c5373ea007b0016b1df40.mockapi.io/room/room?id=1 或https://5f4c5373ea007b0016b1df40.mockapi.io/room/room/1 均能访问id为1的数据

用?id=id访问数据
用/id直接访问数据

但仔细对比一下会发现在js文件中发送带参数的请求只能用’htttps://dataIP/ ‘+id来请求并修改数据,使用’https://dataIP?id=’+id是不可以访问数据的。

感谢byf的帮助

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Theia 使用 VS Code 插件时,可能会遇到 `caches` 未定义的问题。这是因为 `caches` API 是 Service Worker 的 API,而 Theia 并没有内置 Service Worker。因此,在 Theia 无法直接使用 `caches` API。 如果你需要在 Theia 实现缓存功能,可以考虑使用浏览器原生提供的缓存 API,比如 IndexedDB、Web Storage 等。具体来说,你可以在你的 Theia 插件代码使用以下代码来创建一个 IndexedDB 数据库: ```javascript const dbName = 'my-db'; const dbVersion = 1; const request = window.indexedDB.open(dbName, dbVersion); request.onerror = () => { console.error('Failed to open indexedDB'); }; request.onsuccess = () => { const db = request.result; console.log('IndexedDB opened successfully'); }; ``` 然后,你可以在需要缓存数据的地方,将数据保存到 IndexedDB : ```javascript const db = request.result; const storeName = 'my-store'; const transaction = db.transaction([storeName], 'readwrite'); const store = transaction.objectStore(storeName); const data = { key: 'my-key', value: 'my-value' }; const request = store.put(data); request.onsuccess = () => { console.log('Data saved to IndexedDB'); }; ``` 在需要读取缓存数据的地方,从 IndexedDB 读取数据: ```javascript const db = request.result; const storeName = 'my-store'; const transaction = db.transaction([storeName], 'readonly'); const store = transaction.objectStore(storeName); const key = 'my-key'; const request = store.get(key); request.onsuccess = () => { const data = request.result; console.log('Data read from IndexedDB:', data); }; ``` 需要注意的是,使用 IndexedDB 进行数据缓存时,需要考虑到数据版本的管理,避免数据版本升级时出现数据冲突等问题。 希望这些信息能够帮助你。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值