How to access a perl script from within Mojolicious ?

83 views
Skip to first unread message

Aniruddha Pandit

unread,
Oct 15, 2015, 6:40:45 AM10/15/15
to Mojolicious
Im creating a simple web app, and was going to use the Autocomplete Jquery to allow for autocompleting a text field.

From this script :


Example :
                   $(function() {
$("#gene").autocomplete({
source: "states.pl",
minLength: 2,
select: function(event, ui) {
$('#state_id').val(ui.item.id);
$('#abbrev').val(ui.item.abbrev);
}
});


Now how do I get the script to run that source file, states.pl ? Currently it is giving me a 404 Not Found error. I have tried putting the script in the root, public and the folder in which the script for the form exists to no avail.

Thanks,

Anir

Stefan Adams

unread,
Oct 19, 2015, 5:33:43 PM10/19/15
to mojolicious

On Thu, Oct 15, 2015 at 5:40 AM, Aniruddha Pandit <anirudd...@gmail.com> wrote:
Now how do I get the script to run that source file, states.pl ? Currently it is giving me a 404 Not Found error. I have tried putting the script in the root, public and the folder in which the script for the form exists to no avail.

Is states.pl a Mojolicious app?

For testing purposes, and proof of concept:

Start states.pl with something like:
$ mojo states.pl daemon
Update your jQuery with:
source: "http://localhost:3000", (don't specify states.pl because, per the command above, it's already listening on port 3000)

Your jQuery should now send a GET request to http://localhost:3000 which states.pl will handle.

This is a proof of concept to prove to yourself that you can get the Mojolicious app and the jQuery code to work.  You'll then of course update all your locations as your app progresses from PoC to production.

Алексей Орлов

unread,
Nov 30, 2015, 7:32:00 AM11/30/15
to Mojolicious
$("#gene").autocomplete({
    source: "<%= url_for('autocomlete_route_name') %>",
.....

четверг, 15 октября 2015 г., 13:40:45 UTC+3 пользователь Aniruddha Pandit написал:
Reply all
Reply to author
Forward
0 new messages