admin管理员组文章数量:1333429
I can't seem to figure this out. Is this an apache configuration? I've seen some filters.php configurations to add POST but if this was the problem it would be somewhere in laravel docs, right?
Routes:
Route::get('orders/add', 'OrderController@add');
Route::resource('orders', 'OrderController');
Controller (REST methods are empty):
class OrderController extends \BaseController {
public function add()
{
if (Request::ajax())
return "ajax request ";
else
return "not ajax";
}
...
jQuery:
function add()
{
var tid = $('#sites input[type=radio]:checked').attr('id');
$.ajax({
type: "POST",
url: 'add',
data: { tid: tid }
}).done( function (msg){
alert(msg);
});
}
Button to send:
<button onclick="add()" id="formSubmit"> Carrinho </button>
And the error firefox shows me on console when I click the button:
POST http://localhost/orders/add [HTTP/1.0 405 Method Not Allowed 17ms]
Thank you all.
I can't seem to figure this out. Is this an apache configuration? I've seen some filters.php configurations to add POST but if this was the problem it would be somewhere in laravel docs, right?
Routes:
Route::get('orders/add', 'OrderController@add');
Route::resource('orders', 'OrderController');
Controller (REST methods are empty):
class OrderController extends \BaseController {
public function add()
{
if (Request::ajax())
return "ajax request ";
else
return "not ajax";
}
...
jQuery:
function add()
{
var tid = $('#sites input[type=radio]:checked').attr('id');
$.ajax({
type: "POST",
url: 'add',
data: { tid: tid }
}).done( function (msg){
alert(msg);
});
}
Button to send:
<button onclick="add()" id="formSubmit"> Carrinho </button>
And the error firefox shows me on console when I click the button:
POST http://localhost/orders/add [HTTP/1.0 405 Method Not Allowed 17ms]
Thank you all.
Share Improve this question asked Sep 9, 2014 at 4:26 hfinglerhfingler 2,0144 gold badges30 silver badges38 bronze badges2 Answers
Reset to default 4Route::get
expects a GET HTTP header. U'll need to use Route::post
.
Instead of
Route::get('orders/add', 'OrderController@add');
you should use
Route::post('orders/add', 'OrderController@add');
Source: Laravel routing documentation
You really don't need a /add route if you are using a resource controller as it has a create method on it already.
OrdersController extends BaseController {
public function index() {} // show ALL orders
public function create() {} // show the form to create an order aka "add"
public function store() {} // get input from post.
public function update($order_id) {} // update an order resource
public function destroy($order_id) {} // destroy an order resource
}
In your ajax change the url to url: {{URL::route('orders.store')}},
and that should fix it.
本文标签: javascriptjQuery ajax request returning 405 ( POST not allowed) in laravel appStack Overflow
版权声明:本文标题:javascript - jQuery ajax request returning 405 ( POST not allowed) in laravel app - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742304571a2449658.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论