[英]how can I send post request in ajax to laravel route parameters
[英]how to send a variable for route introduced in ajax in laravel
我有一个 Ajax 函数,它调用 laravel 路由,我需要传递一个变量,我做了一些事情,但我并没有因为做得好而破坏它,让我们看看你是否可以帮助我。
我将变量传递给视图的片段控制器
'presupuesto_id' => $presupuesto->id,
函数 Ajax
$("#editar_presupuesto").click(function(){
var url ="{!!route('presupuesto.update',$presupuesto_id)!!}";
$.ajax({
type: "POST",
url: url, // This is what I have updated
data: $("#form_presupuesto").serialize(),
success:function(data) {
}
if (data.errors != "" && data.errors != null) {
}
}
})
});
使用数据属性
你的 html 看起来像这样..
<button type="button" id="presupuesto_id" data-route="{{ route('presupuesto.update',$presupuesto_id)}}">Submit</button>
你的js看起来像这样..
$("#presupuesto_id").click(function(){
let url = $(this).data('route');
$.ajax({
type: "POST",
url: url, // This is what I have updated
data: $("#form_presupuesto").serialize(),
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.