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

由网友(Tender、)分享简介:我想发出一个简单的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...

我想发出一个简单的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 http://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: http://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.

阅读全文

相关推荐

最新文章