Ok, I found the solution which utilizes the Dancer2::Plugin::Ajax module and is much cleaner.
The route is now
ajax '/p_details/:tab' => sub { return params->{tab}; };I dropped the 2 javascript functions (partner_details and partner_tab) previously posted and am now using this function.
function partner_details(tab) { $.ajax({ url: "/p_details/" + tab, success: function( data ) { $( "#folder" ).html( data ); } }); };
That other js function was moved to the external js file to remove the clutter in the template file, which is now:
<script> init_folder_tabs(); </script> <span id="top"> <h2>Partner Details</h2> <h3>The partner details function is still in development and is not ye +t ready to be used.</h3> </span> <ul id="tabs"> <li><a href="" onclick="partner_details('general')">General</a></li> <li><a href="" onclick="partner_details('qualifier')">EDI Qualifier +/ ID</a></li> <li><a href="" onclick="partner_details('certificates')">Certificate +s</a></li> <li><a href="" onclick="partner_details('contact')">Contact Informat +ion</a></li> <li><a href="" onclick="partner_details('notes')">Notes</a></li> </ul> <div id="folder"></div>
So, now when I click on the "folder tab" link, it displays the tab name as the main content of the "folder". Now I just need to write the sub that queries the db and builds the table to be displayed.
In reply to Re: How to make ajax requests in Dancer2
by fishmonger
in thread How to make ajax requests in Dancer2
by fishmonger
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |