How can i pass the id in ajax url
I need to pass the id in ajax, i have something like:
url: '{{ URL::route(delete_hub{{id}}) }}',
or
url: '(delete_hub{{id}}',
I got an strange url when i call the ajax, how can i pass the id correctly ?
When ajax is called i got the url like: delete_hub%7B%7B%20id%20%7D%7D
url: 'delete_hub' + {{ id }},
btw , which javascript are you using? jquery ? pure js? or vue?
jquery, that will output syntax error.
I need to grab the id without having to save to js variable then pass if as data, this way i can. I want to do it a bit smarter, just grab it.
#In the HTML form
You write the route name with the id as an empty value
action= "{{route('name route','')}}"
#in JQuery
var url= $('form').attr('action')+'/'+id;
$.ajax({
url:url,
method:'post',
data:data,
success:function (res) {
console.log(res)
}
})
url: "{{url('delete_hub')}}"+'/'+id,
$.ajax({
url:"{{route('user.delete', '')}}/"+id,
method:'post',
data:data,
success:function (res) {
console.log(res)
}
});
@Shaan24k you are getting blade and javascript mixed up
@Snapey either you can pass the global variable in javascript to access in .js file. it depends on situation.
Please or to participate in this conversation.