Nicholas Mabe

Nicholas Mabe

  • 1.6k
  • 72
  • 4.3k

How to filter an ajax url call with a variable in the URL?

Jan 15 2021 1:43 PM
I'm a bit stuck, any help is gratefully received.
 
I’m opening a view with the following address: https://localhost:44322/Admin/Account/Details/3
 
At this point it has filtered out the account I’m looking for which has the Id 0f 3. It returns the relevant data. Also on the view is a Datatable which also needs to be filtered with the same ID.
 
the datatable calls the data as follows:
 
" function loadDataTable() {
dataTable = $('#tblData').DataTable({
"ajax": { "url": "/Admin/Account/DetailsByAccount" },
 
If I change it to:
 
function loadDataTable() {
dataTable = $('#tblData').DataTable({
"ajax": { "url": "/Admin/Account/DetailsByAccount?Id=3" },
 
I get all the related records for the Account with the ID of 3, just what I’m looking for.
 
I’ve tried everything I can find to get the dynamic variable from the URL into the ajax url string but the only thing I’ve got is a headache.
 
Any help is gratefully received.

Answers (2)