Re: Calling a perl function from within a javascript function
by dws (Chancellor) on Jun 26, 2002 at 00:08 UTC
|
Second off, is this a stupid way of achieving what I want to do?
"Stupid" is a rather strong word, but yes, it is an ill-advised approach. Let's assume you sort out the particulars of issuing requests to a server for more data without moving off of the current page. (This can be done, with hidden frames and Javascript.) The killer will be performance.
Dynamically requesting new data as the mouse wanders over an images is a viable approach for a fat UI that has a short and fast pipe to underlying data, but for a web-based application, performance is going to SUCK. The lag between determining that you need to fetch data for more cities and that data being available in the browser will driver your users up the wall. (It did to our users when we tried something similar.)
I think your best bet is to generate a fatter page initially, with city data in Javascript data structures that you can query in the browser.
| [reply] |
Re: Calling a perl function from within a javascript function
by tadman (Prior) on Jun 25, 2002 at 23:42 UTC
|
Short answer: Write a Java applet if you want something to work like that. You can send XML from your Perl script to the Java program, which could presumably display it. This isn't easy though. It sounds like the Golden Hammer of solutions, in other words, a waste of time.
Long answer: Make a bigger map and label it so that it makes sense as to what people are looking at. Also, you can easily generate JavaScript code from within Perl. With that in mind, you can export a JavaScript array which would have coordinates and town names. You can't "call" Perl from within JavaScript, because there is no Perl. There is only a Web server somewhere, with Perl running on it.
As long as the page you're talking about can be converted into a Perl-generated one, then you have a lot of ways you can go about solving this problem.
| [reply] |
|
|
My map fits the vertical length of the screen already, and thers about 100 sectors so theres no room on it for text. I'm using gd.pm to shade the map.
I dont understand what you mean by "there is no Perl". Is there not a JavaScript equivalent of perls get function. If there was, I could have the perl script print out the town names, and this would be received by the JavaScript equivalent of get().
Maybe I'm missing something here, I started Internet based programming less than a year ago so my knowledge is patchy to say the least.
| [reply] |
|
|
In that perfect world where we all live together in perfect harmony, the sky is always blue, the grass is always green, and VB never came into being, yes, there is a JavaScript get() function.
In the really real world, though, such a thing would be considered a munition. Your browser could be commanded by a third-party to do whatever they choose, such as probe sites with IIS attacks, send files from your computer, or just cause general mayhem (i.e. DDOS).
There is no "get()" function, no.
With a little creativity, though, you can swap images in a clever way to simulate animation and/or server-side loads. Check your JavaScript reference on how to do this, because this is clearly not a Perl question at this point.
| [reply] |
A reply falls below the community's threshold of quality. You may see it by logging in.
|
Re: Calling a perl function from within a javascript function (using PerlConnect)
by broquaint (Abbot) on Jun 26, 2002 at 12:00 UTC
|
First off, can I call a perl function from within a javascript function
Why of course you can my good monk! This is perl after all where it's not uncommon to call on the power of quantum superpositions to perform a list operation. To do this will require the download and compilation of the JavaScript engine SpiderMonkey. Within the source package you should find the PerlConnect library which allows you to call both Perl in JavaScript and JavaScript in Perl (hmmm, time to implement Inline::JS methinks). Here's some example JS using PerlConnect
p = new Perl;
p.use('Time::gmtime');
t = p.eval('Time::gmtime::gmtime');
// returns [49,0,4,24,6,98,5,204,0]
Unfortunately no browsers will have PerlConnect built into them (well I certainly hope not - security etc) so this won't be of much use to you I'm afraid, but I didn't want the Monastery to go uninformed of this possibility ;-)
HTH
_________ broquaint | [reply] [d/l] |
Re: Calling a perl function from within a javascript function
by peschkaj (Pilgrim) on Jun 26, 2002 at 03:56 UTC
|
I would use the perl on the server to create an array or some other structure, as DWS suggests.
I, personally, would do it as follows: 1) Create an image map with numbered regions. 2)Create an array whose index corresponds to the number regions. 3) onmouseover call a function that looks like this:
<element onmouseover="bogus(this);">
function bogus(element) {
var mouseOver = element + "name";
var visiElem = document.getElementById(mouseOver);
visiElem.style.visibility = "visible";
}
Or something like that.
It is possible to do what you want by using XMLHttpRequests, but the page will only be accessible to NS/Moz and IE5.5/IE6.
I'm sure that if wrote something pretty special, you could cause perl code to be executed through javascript, but it would probably have to be pretty special.
| [reply] [d/l] |