Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: How to make ajax requests in Dancer2

by fishmonger (Chaplain)
on Aug 26, 2014 at 20:45 UTC ( [id://1098672]=note: print w/replies, xml ) Need Help??


in reply to How to make ajax requests in Dancer2

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1098672]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-18 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found