I need to pass route parameter with ajax
but I am using named route method in ajax
code.
route I want to go Route
Route::post('/edit/{id}', 'ArticleController@updateArticle')->name('updateArticle');
Ajax
var id= $("input[name=editId]").val();
$.ajax({
type:'POST',
enctype: 'multipart/form-data',
url:"{{ route('updateArticle',"id") }}",
data: formdata,
contentType: false,
processData: false,
success:function(data){
$('.alert-success').html(data.success).fadeIn('slow');
$('.alert-success').delay(3000).fadeOut('slow');
}
});
I want to use variable id
in ajax
URL.
Laravel Ajax Form Validation Tutorial so open your routes/web. php file and add the following route. Location:- Root/routes/web. php Route::get('my-form','HomeController@myform'); Route::post('my-form','HomeController@myformPost')->name('my.
How Pass URL in laravel ajax? $. ajax({ url: url, type: 'DELETE', data: { id: userID }, success: function() { alert("YES"); }, error: function() { alert("NO"); } }); I would suggest using Axios instead of jQuery for this. It is a little more expressive / easy to follow / more common.
How to pass javascript variable to laravel route? You can pass javascript variable value to laravel route on ajax call. You have to use a placeholder to generate the URL and after that replace value by using replace method and pass the value to url parameters of ajax method.
I had the same problem, just change your ajax url with this one.
var id= $("input[name=editId]").val();
$.ajax({
type:'POST',
enctype: 'multipart/form-data',
url:"{{ route('updateArticle') }}" + '/' + id,
data: formdata,
contentType: false,
processData: false,
success:function(data){
$('.alert-success').html(data.success).fadeIn('slow');
$('.alert-success').delay(3000).fadeOut('slow');
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With