【问题标题】:Laravel Ajax Patch not workingLaravel Ajax 补丁不起作用
【发布时间】:2015-04-17 10:30:49
【问题描述】:

试图弄清楚如何使用 ajax 进行修补。当我按下 btnUpdate 按钮时,我希望 ajax 修补“某些东西”。

在我的路由器中:

 Route::patch('forecasts/edit/{id}',['as'=>'forecasts.edit',
                       'uses'=>'forecastsController@handleEdit']);   

在我的控制器中:

    public
            function handleEdit($id)
    //handle edit form submission
        {

        $data=Input::all(); 
        return $data; //just want  to see something
        }

在我看来html:

<div>
   <button type='button'id="btnUpdate" name="btnUpdate">Update</button>
</div>

在我看来脚本:

$("#btnUpdate").click(function () {
$.ajax({
           type: "PATCH",
           url : base_url+'/forecasts/edit/'+forecast_id,                    
           data :  "Something",  success: function (data) {
           alert(data);
        }
    });
});

【问题讨论】:

    标签: javascript php ajax laravel-4


    【解决方案1】:

    您的 ajax 网址似乎是错误的。尝试使用路由等辅助函数。

    $.ajax({
               url : "{{route('forecasts.edit',forecast_id)}}",                    
            }
        });
    });
    

    用于编辑的 URL 模式类似于 htt://base_url/somefunction/{id}/edit

    【讨论】:

    • 这给了我 ErrorException (E_UNKNOWN) 使用未定义的常量 forecast_id - 假定为 'forecast_id'
    • base_url+'/forecasts/edit/'+forecast_id 我从你提到的变量中得到这个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多