Forum Moderators: open

Message Too Old, No Replies

Exec. Perl Script from JavaScript

         

Edge

7:38 pm on Sep 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Here is what I have (it works BTW):

<div class="test">
html JS code
</div>

<script type="text/javascript">

function test()
{ if ($('.test').height() == 0)

alert("text displayed to screen") ;}
$(test);
</script>


This script works by throwing a popup alert to my visitor if the html within the div class html does not display - therfore the height is zero.

What I want instead of the popup Alert is to execute a perl script.

The address would be something like:

/cgi-bin/perlscript.cgi

Any help is appreciated.

Thanks

daveVk

3:26 am on Sep 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What to you intend to do with reply ?

If you just wish to execute it and ignore reply, create or find an iframe element and set source.

iframeElement.src="/cgi-bin/perlscript.cgi";

If you need to process reply then AJAX is probably required.

Edge

1:14 pm on Sep 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks Dave,

My simple plan is that when the java contents of <the div class="test"> does not produce text results is to replace the contents with the results of my perl script.

daveVk

12:23 am on Sep 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming you are using jquery ( other libraries have similar )

$.get('/cgi-bin/perlscript.cgi', function(data) {
$('.test').html(data);
});

[api.jquery.com...]

Edge

2:21 pm on Sep 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



DaveVk,

First, thank you for your help - your'e very knowledge-able. As you have figured out, I'm getting an education.

All you have suggested works.

One challenge that I was seeing in larger IE html files is that the script seemed to execute everytime whether my div class is zero or not and I got the result of my cgi script. Where in Firefox the routine appeared to work properly everytime.

I put a setTimeout in the script and it seems to works every time in IE. I hope I understand setTimeout right...

Here is what I have:

I put jquerty load in the header


<div class="test">
<script type="text/javascript">
html JS code
</script>
</div>


<script type="text/javascript">

function redirect()
{ if ($('.test').height() == 0)

$.get('/cgi-bin/perlscript.cgi ', function(data) {
$('.test').html(data);
});
}

function delay()
{
setTimeout("redirect()",3000);
}
</script>

Edge

6:57 pm on Sep 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Ok, time out - disregard my previous post -this is not the solution.

The script works fine until I put it in a <table>. The DIV height then is =0 even if the js html script executes.

For some reason the "if" portion thinks the height is zero and executes thus overwriting the initial js script.

Working on it...

daveVk

4:27 am on Sep 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[api.jquery.com...]

The function 'redirect' plus the following statement should go in the header script

$(document).ready( redirect ); // or other varient see link

This will wait until the page is loaded ( and sized ) before checking the 'test' div. There is no need for timeouts.