weixin_33688840 2015-10-10 19:58 采纳率: 0%
浏览 16

Laravel Ajax发布异常

I have a select box. And i'm redirecting clients via select box. When they select they are redirecting.

Before i started to write code with laravel my system was working. After laravel i have a problem with this matter.

$('#parent_products').change(function(){
            productid = $(this).val();

            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });

            $.ajax({
                type: 'POST',
                url: '{{ route('redirectVariant') }}',
                data: {
                    productid : productid,
                    _method   : 'PATCH'
                },
                error: function(jqXHR, exception) {
                    alert('Hata 
' + jqXHR.responseText);
                },
                success: function (data) {
                    window.location.replace(data);
                }
            });
        });

I'm getting this error.

MethodNotAllowedHttpException in RouteCollection.php line 219:

This is my route

Route::group(['prefix' => 'ajax'], function () {
        Route::post('product/redirect_variant', [
            'uses' =>'AjaxController@redirectVariant',
            'as'   => 'redirectVariant',
        ]);
    });

Here is my controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class AjaxController extends Controller
{
    public function redirectVariant(Request $request){
        dd(Request::all());
    }
}

What is the problem ?

  • 写回答

1条回答 默认 最新

  • larry*wei 2015-10-10 20:10
    关注

    Your Javascript is spoofing a PATCH request, while your route is setup for POST.

    You could try:

    Route::group(['prefix' => 'ajax'],     function () {
        Route::patch('product/redirect_variant', [
            'uses' =>'AjaxController@redirectVariant',
            'as'   => 'redirectVariant',
        ]);
    });
    
    评论

    报告相同问题?

    悬赏问题

    • ¥15 如何利用闲置机械硬盘变现
    • ¥15 信号处理中的凸优化问题
    • ¥15 arm虚拟机无法和物理机互通
    • ¥15 Android导航条遮盖异常
    • ¥15 计算机网络技术基础问题
    • ¥15 设置mac系统只能访问指定网站
    • ¥15 西门子博途 s7 1200控制三台步进电机
    • ¥15 基于非参数的方向距离函数求污染物影子价格(有偿)
    • ¥15 vue+element 生成table
    • ¥15 实验 4 FIFO 算法和 LRU 算法-C 程序实现