I am fetching the data from database using AJAX in laravel. Its working fine. Following is the code of my AJAX:
$('#salesmanlist_input').on('change', function() {
var salesmanlist_input = $(this).val();
$.ajax({
type: 'GET',
url: 'sales/lims_salesman_list',
data: {
data: salesmanlist_input
},
success: function(data) {
console.log("Data in on change salesman is: " + data);
}
});
});
the route I’m using for it is as follows
Route::get('sales/lims_salesman_list', 'SaleController@limsSalesmanList')->name('SalesmanList.view');
The problem i’m facing is, its working fine on one blade but not working on other blade. On other file its giving the error as
jquery.min.js:2 GET http://localhost/alimran_final/sales/sales/lims_salesman_list?data=usama
2
Answers
The url
url: 'sales/lims_salesman_list',
is static. As it will be added to the current url. You should add the url in blade by using the helperroute
.the Problem You are Facing is that the Route is static,though when you are at /sales url it will also add another sales
as happened to you
you have 2 solutions:
url: ‘sales/lims_salesman_list’, to url: ‘/sales/lims_salesman_list’,
slash added to begining
However I prefer to use Solution 2 hence its more dynamic whenever you change lines in web routes file it will dynamically change
Also try to clear route’s Cache