Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
189
rated 0 times [  195] [ 6]  / answers: 1 / hits: 71400  / 10 Years ago, wed, december 24, 2014, 12:00:00

How Can I pass the variable (stock.id) return from Ajax response to the route to generate the url to edit a stock




$.ajax({
url: 'sectors/stocks/' + $(this).data('sector-id'),
dataType:'json',
beforeSend:function() {
$('.stocks_list').html('Loading...');
}
})
.done(function(data) {
$('.stocks_list').html('<ul>');
$.each(data, function(index, obj_data) {
$.each(obj_data.stocks, function(indx, stock) {
$('.stocks_list').append('<li><a href={{route(admin.stocks.edit,'+stock.id+')}}>' + stock.symbol + ' </a></li>');
});
});
})

More From » laravel

 Answers
12

You can first use a placeholder to generate the URL with and then replace that in javascript.



var url = '{{ route(admin.stocks.edit, :id) }}';
url = url.replace(':id', stock.id);
$('.stocks_list').append('<li><a href='+url+'>' + stock.symbol + ' </a></li>');

[#68401] Saturday, December 20, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aidanl

Total Points: 156
Total Questions: 102
Total Answers: 112

Location: Saint Lucia
Member since Wed, Feb 8, 2023
1 Year ago
;