This may be a question for the Javascript forum, but I think my problem lies on the CGI side of things. I'm trying to include dynamic information in a page that's already dynamically generated by a cgi (a different one).
I've heard of a technique whereby you use javascript to include the output of a script, so I'm basically inserting this javascript include into the template that the main CGI fills in. The problem is, it doesn't work.
Here's what I put in the page.
<script src="url/test/hello.cgi" language="text/javascript"></script> The idea is that 'hello.cgi' will output html through a series of 'document.write()' statements that the browser will print as html.
Here's my hello.cgi:
#!/usr/local/bin/perl
print "Content-type:application/x-javascript\n\n";
print "document.write(\"hello there\")\n\n";
exit; Basically nothing happens when I call the html file with the js including. When I point directly at hello.cgi, though, it says 'document.write(/"hello there\")'.
I suspect this is a problem with the way Perl is outputting, but I really don't know what to do. Has anyone had experience with this technique?
Thanks for any suggestions/comments/better ideas.
Zach
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title></title>
<script type="text/javascript" src="http://path_to/js.pl"></script>
</head>
<body>
</body>
</html>
Tip: you can use
print qq$document.write("hello there")$; to avoid having to escape all the quotes. You can use pretty much any other ASCII character instead of $ sign as long as they are paired.