POST 405(方法不允许)尝试后AJAX请求时

编程入门 行业动态 更新时间:2024-10-09 06:30:07
本文介绍了POST 405(方法不允许)尝试后AJAX请求时 - Laravel 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想发出一个简单的AJAX请求来填充Laravel菜单,但是,我有很多的麻烦得到它才能正常工作。

I am trying to issue a simple AJAX request to populate a menu in Laravel, however, I am having a lot of trouble with getting it to work properly.

我不知道是什么问题,并搜索了几个小时后,我找不到任何可以提供帮助。

I am not sure what the issue is, and after a couple hours of searching, I cannot find anything that can help.

下面是我的AJAX请求:

Here is my AJAX request:

$.ajax({ type: 'POST', url: '/ajax/populateApiAuth', data: json, dataType: 'JSON', success: function (json) { alert('test'); return true; }, error: alert('fail') });

我到了AJAX回调路线:

My route to the AJAX callback:

Route::get('/ajax/populateApiAuth', 'ApiController@populateApiAuth');

和我的控制器来处理Ajax回调ApiController:

and my controller to handle the AJAX callback in ApiController:

public function populateApiAuth() { return Response::json(array('msg' => 'test'); }

当发送AJAX请求时,它在错误的参数失败消息返回,并在控制台,它告诉我:

When sending the AJAX request, it returns with the fail message in the error parameters, and in the console, it tells me:

POST localhost:8000/ajax/populateApiAuth 405 (Method Not Allowed)

研究此错误信息,它的结果作出一个POST请求到不同的域/服务器?这怎么可能?

Researching this error message, it results from making a POST request to a different domain/server? How can this be?

我曾尝试使用绝对URL的AJAX请求有:

I have tried to use an absolute URL for the AJAX request with:

url: '{{ URL::to("ajax/populateApiAuth") }}

这使完整的URL:的http://本地主机:8000 / AJAX / populateApiAuth 但是,这并不解决问题,无论是

which gives the full URL: localhost:8000/ajax/populateApiAuth but that does not solve the issue either.

推荐答案

这岂不是你的问题?

Route::get('/ajax/populateApiAuth', 'ApiController@populateApiAuth');

您设置路由了GET请求,但你试图通过一个POST请求来访问它。

You set the route up for GET requests, but you're trying to access it via a POST request.

更多推荐

POST 405(方法不允许)尝试后AJAX请求时

本文发布于:2023-10-10 18:31:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479387.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不允许   方法   POST   AJAX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!