项目遇405错误 - Method Not Allowed、Request method 'DELETE' not supported

版权声明:★Study hard and make progress every day.☺★ https://blog.csdn.net/qq_38225558/article/details/86505303

最近在写项目中遇见405错误,Method Not Allowed、Request method 'DELETE' not supported 如下:

坑人的很,网上百度了解了一下,有如下几种说法:

①有说axios与ajax发送请求后,后端响应回来的什么类型不同什么滴...

②前端发送的请求与后端接收的请求类型不一致,比如前端发get请求,后端却用的是post

③就是如下我犯的错:

我后端用的是springboot架构写的,这里我用的是restful风格处理的删除

我的前端vue框架中发送请求的代码如下:

//删除
handleDel: function (index, row) {
	this.$confirm('确认删除该数据吗?', '提示', {
		type: 'warning'
	}).then(() => {
		this.listLoading = true;
		let para = { id: row.id };
		this.$http.delete("/product/brand/delete/",para)
				.then((res) => {
					this.listLoading = false;
					this.$message({
						message: '删除成功!',
						type: 'success'
					});
				});
	}).catch(() => {

	});
},

405错误原因是因为后端我用的是restful风格,前端发送请求的时候必须将id带入url中一起发送到后端!!

最后前端vue解决后的代码如下:

最后测试删除成功 - 405错误成功解决!!

猜你喜欢

转载自blog.csdn.net/qq_38225558/article/details/86505303