mysql> desc test; +--------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | number | decimal(4,2) | NO | | NULL | | +--------+--------------+------+-----+---------+----------------+ 2 rows in set (0.00 sec) mysql> select @@sql_mode; +--------------------------------------------+ | @@sql_mode | +--------------------------------------------+ | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | +--------------------------------------------+ 1 row in set (0.00 sec) mysql> select * from test; Empty set (0.00 sec) mysql> insert into test(id,number) value(NULL,100); ERROR 1264 (22003): Out of range value for column 'number' at row 1 mysql> SET SESSION sql_mode='NO_ENGINE_SUBSTITUTION'; Query OK, 0 rows affected (0.00 sec) mysql> insert into test(id,number) value(NULL,100); Query OK, 1 row affected, 1 warning (0.00 sec) mysql> select * from test; +----+--------+ | id | number | +----+--------+ | 1 | 99.99 | +----+--------+ 1 row in set (0.00 sec)
fetch('https://reqres.in/api/users/',{ method: 'POST', headers:{ 'Content-Type':'application/json' },//注意在body发送json时需要正确设置请求头的 Content-Type body: JSON.stringify({ name:'User 1' }) //注意在body发送json时,不能直接使用json对象,要使用JSON.stringify方法将json对象转为字符串 }) .then(res=> { if(res.ok) { // 此处加入响应状态码判断 console.log("Successful") return res.json() }else{ console.log("Not Successful") } }) .then(data=>console.log(data)) .catch(error=>console.log(error)) //注意此处只对网络无法连接或者服务器响应超时报错,如果状态码返回404或其他状态码此处不会报错