Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialVincent Asta
2,330 PointsCan I use JavaScript to interact with Perl on a web server?
Is it possible to have a web server execute a Perl script using a js variable captured from a prompt to a user?
For example: 1.) Web page (with .js file) is loaded on end user's machine 2.) .js prompts user for a variable 3.) variable 'blah' is captured 4.) Perl script is then executed with blah passed to it 5.) The result from that Perl script is returned to the web page for the user to view (alert, another page, etc.)
I'm hoping this makes some sense, not sure if I am formulating the question correctly, or if there is more info I can provide which would be helpful.
I just wanted to know if I am 'on the right track' so-to-speak, or if I should go down another track, i.e. PHP, RoR, etc.
1 Answer
Chris Shaw
26,676 PointsHi Vincent,
First off just a quick FYI that w/ is short for without, I've updated your posts title so it's not confusing.
To answer your question yes you can absolutely use JavaScript to make requests to any back end language such as perl, in your JavaScript you need to make what's known as an XMLHttpRequest which built into all browsers the same way as of IE9.
I'm typing this on my mobile so it's a bit hard to get some running examples but if you see the below link it has a lot of useful information until I get into work.
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest
Vincent Asta
2,330 PointsVincent Asta
2,330 PointsHello Chris,
I updated the title of my post to make it more clear, thanks for the feedback.
Thanks for the reply on usage of JavaScript. I'll check this link out to see what is behind making this work. If you did come across a working example, I would appreciate it very much.
Iain Simmons
Treehouse Moderator 32,305 PointsIain Simmons
Treehouse Moderator 32,305 PointsSlightly off-topic, but w/ is short for 'with', w/o is short for without... :)