【发布时间】:2018-07-10 18:47:47
【问题描述】:
在我的开发机器上,POST、PUT、DELETE、GET 方面一切正常。
例如:
POST https://example.com/laravel/project (will create a new project - with data coming in from ajax)
PUT https://example.com/laravel/project/1 (will update the content of project with ID 1)
DELETE https://example.com/laravel/project/1 (will delete the project with ID 1)
但是,我将我的项目转移到生产环境(不同的服务器),现在
POST https://example.com/laravel/project (will create a new project as expected)
PUT https://example.com/laravel/project/1 (will not **update** project 1)
DELETE https://example.com/laravel/project/1 (will **not** delete project 1)
我检查了 chrome 的网络选项卡,我可以看到存在的 cookie 以及来自 ajax 调用的数据(例如,更新/修改的字段)。
另外,我的状态为 200,因此据我了解,网络服务器上也没有任何问题。
下面是我的 ajax 调用示例 - 它们位于 $.ajax 中,并具有成功和失败功能。只显示重要的部分:)
type: 'POST',
url: '/laravel/project',
data: {
'_token': $('input[name=_token]').val(),
'project_name': $('#project_name_add').val(),
'category': $('#category_add').val()
}
type: 'PUT',
url: '/laravel/project/' + id,
data: {
'_token': $('input[name=_token]').val(),
'project_name': $('#project_name_edit').val(),
'category': $('#category_edit').val()
},
但是,它实际上并没有更新或删除任何内容。
感谢您的帮助。
【问题讨论】:
-
尝试为方法
_method添加一个隐藏字段spoofing -
@Webinion 实际上,HTML 表单需要 _method,但 ajax 不需要。
-
是的,我知道,但请尝试一下。还要检查控制台并查看正在为 AJAX 发出的请求。
-
@Webinion 好的,从开发中它可以很好地使用类型:POST,然后添加 _method 和 PUT。现在我需要在直播/生产服务器上试用它。任何想法为什么它在开发中运行良好?
-
请求显示为 POST,因为我将其更改为 POST,然后使用 _method PUT。这是在开发服务器上。一旦我获得访问权限,将回复。谢谢。
标签: ajax laravel http-delete http-put