啊麟 发表于 2024-4-3 01:56:06

GM_xmlhttpRequest 无法发送到后端

!(data/attachment/forum/202404/03/015319sdyx1die9y7a97ex.png)

### 提交的数据没有问题。用api工具测试过了,但猫会报错

## 报错信息
```
{
    "finalUrl": "http://localhost:3000/ymbz/add",
    "readyState": 4,
    "status": 400,
    "statusText": "Bad Request",
    "responseHeaders": "connection: keep-alive\r\ncontent-length: 93\r\ncontent-type: application/json; charset=utf-8\r\ndate: Tue, 02 Apr 2024 17:53:54 GMT\r\netag: W/\"5d-iRfbrqUfoPgaWSHtZg9KFnoQQm4\"\r\nkeep-alive: timeout=5\r\nx-powered-by: Express\r\n",
    "response": "{\"message\":\"Unexpected token o in JSON at position 1\",\"error\":\"Bad Request\",\"statusCode\":400}",
    "responseText": "{\"message\":\"Unexpected token o in JSON at position 1\",\"error\":\"Bad Request\",\"statusCode\":400}"
}
```

李恒道 发表于 2024-4-3 02:18:59

json是指http或者gateway解析数据的方式,不是代表本地提交的格式

提前JSON序列化一下

王一之 发表于 2024-4-3 09:51:51

data只能传字符串和FormData类型的数据

要传json得先序列化一下
页: [1]
查看完整版本: GM_xmlhttpRequest 无法发送到后端