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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.