扩展范围"methodNotAllowed"错误


  • Laravel版本:5.3.31

描述:

我在项目的两个不同页面上有完全相同的 ajax 调用,但我在其中一个页面中收到"方法不允许"错误。

我的网站.php:

Route::post('/seccion', 'FiltrosController@getSecciones')->name("filtro.secciones");

我的 AJAX 调用:

$.ajax({
type: "post",
url: "{{ route("filtro.secciones") }}",
data: $("#form").serialize(),
dataType: "json",
success: function (datos) {
//mycode
},
error: function (request, status, error) {
console.log(error);
}
});

以下是有效的调用标头:

Request URL:http://192.168.99.100:3001/seccion
Request Method:POST
Status Code:200 OK
Remote Address:192.168.99.100:3001
Referrer Policy:no-referrer-when-downgrade

我得到的响应标头:

Cache-Control:no-cache
Connection:Keep-Alive
Content-Length:457
Content-Type:application/json
Date:Mon, 07 Aug 2017 19:26:43 GMT
Keep-Alive:timeout=5, max=97
Server:Apache/2.4.10 (Debian)

好的,在这种情况下一切正常。但是在另一个页面中,我进行了相同的ajax调用,并且得到了这个:

Request URL:http://192.168.99.100:3001/seccion
Request Method:POST
Status Code:405 Method Not Allowed
Remote Address:192.168.99.100:3001
Referrer Policy:no-referrer-when-downgrade

以及失败的调用的响应标头:

allow:POST
Cache-Control:no-cache, private
Connection:close
Content-Type:text/html; charset=UTF-8
Date:Mon, 07 Aug 2017 19:26:57 GMT
Server:Apache/2.4.10 (Debian)
X-Powered-By:PHP/7.1.7

我们可以看到响应标头中允许 POST,但我得到这个"代码:405 方法不允许">

我不知道什么是快乐,有什么线索吗?

谢谢。

问题是我将"{{ method_field('PATCH'( }}"放在包装触发 ajax 调用的选择下拉列表的形式中,因此在 ajax 调用的数据中传递具有"PATCH"值的_method参数并抛出"methodNotAllowed"错误。

我修复了它只是传递我需要的数据,而不是所有序列化的表单:

$.ajax({
type: "post",
url: "{{ route("filtro.secciones") }}",
data: $("#form").find('#zonas').serialize(),//<-- solution 
dataType: "json",
success: function (datos) {
//my code
},
error: function (request, status, error) {
console.log(error);         
}
});

最新更新