0

Inside the cgi-bin folder, I have an experiment.cgi:

#!/usr/bin/perl -w

use DBI;
use CGI qw(:standard);
require "../common/config.pl";

print header;
print start_html(-title=>"Add Assignment");


print<<EOT;
  <script type = "application/javascript" src = "experiment.js"></script>
EOT

print h2("Add New Automated Assignment");

# print<<AEOT;
#   <script>experiment();</script>
# AEOT
print end_html;

In the same folder I have experiment.js

function experiment(){
    alert('ghello world');
}

However there is problem with the experiment.js file inclusion. In the log files I get the following error:

End of script output before headers: experiment.js

I searched for this error and found it was relate to cgi files. So my guess is that apache2 is interpreting experiment.js as a cgi file. Am I right in this? If yes, what is the proper way to set it up so that JavaScript and cgi could be used together?

1
  • Warning: The use of CGI.pm is not recommended, it has been removed from Perl Core. Commented Mar 13, 2016 at 9:19

1 Answer 1

3

I searched for this error and found it was relate to cgi files. So my guess is that apache2 is interpreting experiment.js as a cgi file. I am right in this?

Yes

If yes, what is the proper way to setup so that javascript and cgi could be used together.

Don't put non-CGI programs in your cgi-bin. Put them with the rest of your static files.

You'll need to adjust the URL. src="/js/experiment.js" for example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.