I've been twisting around my code for a couple of hours now but no luck in getting the right approach of putting a javascript variable inside laravel url(). The variable is taken as a string whenever I placed it as a parameter inside the url(). Below is my code. Please help.
javascript file
function generateSchedule( id, loan_type ){
var txt_url;
if( loan_type == "Business" ){
txt_url = 'addamortbusinessloan';
}else{
txt_url = 'addamortization';
}
$.post('{{ url("'+txt_url+'") }}', {'loanId':id}, function(data){
},"json");
}
This is not working {{ url("'+txt_url+'") }}. I have been twisting the quotes placement but no luck at all. The result of this is http://localhost:8000/txt_url. I want it to be like this http://localhost:8000/addamortbusinessloan or http://localhost:8000/addamortization
generateScheduleis called in the browser. So that txt_url variable doesn't exist in JavaScript at all, which is why your template engine renders the static value you see.