gpt4 book ai didi

javascript - MethodNotAllowedHttpException Ajax Laravel 5.3 在带有参数的路线上

转载 作者:行者123 更新时间:2023-12-03 05:09:08 25 4
gpt4 key购买 nike

我有简单的操作,例如使用 ajax 从数据库中检索国家/地区名称:

$.ajaxSetup({headers:{'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}});
$.ajax(
{
url: 'country',
type: "post",
async: asynchron,
data: data,
dataType: "json",
...

它适用于具有简单路由的页面,例如:

Route::get('add_property', 'ViewController@add_property');

但问题是在带有参数 URL 的页面中,例如:

Route::get('mod_property/{ref}', 'ViewController@mod_property')->name('mod_property');

它不起作用,并且在网络调试窗口中的响应预览中,即使参数路由不是我从 ajax 函数调用的路由,它也会显示 MethodNotAllowedHttpException ,事实上就是这个:

Route::post('country', 'SimpleOperationsController@country');

那么,如何让 ajax 在带有参数 URL 的页面中工作?

最佳答案

url: 'country', 更改为 url: '\country', 以防止相对路径。

关于javascript - MethodNotAllowedHttpException Ajax Laravel 5.3 在带有参数的路线上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41898024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com