Hello monks
Recently I was trying to rewrite the sucking php mailform and replace it with cgi/perl. I got a werid error 403 when XMLHttpRequest is sending my variables. Here is some code

AJAX

var dataObj = { 'do0' : '', // name 'do1' : '', //email 'do2' : '', //sunject 'do3' : '' // text }; /* create the new xmlhttp req here */ function createXMLHttpRequest() { var http = false; if ( window.XMLHttpRequest ) { try { http = new XMLHttpRequest(); } catch (e) { http = false; } } else if ( window.ActiveXObject ) { try { http = new ActiveXObject("Msxml2.XMLHttp"); } catch (e) { try { http = new ActiveXObject("Microsoft.XMLHttp"); } catch (e ) { http = false; } } } return http; } // simple testing assumes everything is ok :) window.onload = function() { document.getElementById("sender").onclick = function() { for ( var i=0; i < 4; i++) { dataObj['do'+i] = document.getElementById("do"+i).valu +e; //alert(dataObj['do'+i]); } var nr = new XMLHttpRequest(); var sent = "cgi-bin/ex2.pl?name="+dataObj['do0']+"&email=" ++dataObj['do1']+"&subject="+dataObj['do2']+"&text="+dataObj['do3']; nr.open('post', sent, true); nr.send(); } }

And the CGI...

CGI

#!/opt/lampp/bin/perl use strict; use warnings; use CGI; my $p = new CGI; my ($name, $email, $sub, $txt) = ( $p->param('name'), $p->param('email'), $p->param('subject'), $p->param('text'), ); $p->header; print "$name\n$email\n$sub\n$txt\n"; exit(0);

In my firebug the POST is sended but it shows me: POST http://localhost/cgi-bin/ex2.pl?name=c&email=a&subject=b&text=ff 403 Forbidden

Can you help me here? I have no idea why is this happening, I`ve chmodede my perl script with 777 and 755 no effect... I am running on arch linux XAMPP btw.

Fixed

It appears that adding this:

<Directory "/opt/lampp/cgi-bin"> AllowOverride None Options ExecCGI # this one Order allow,deny Allow from all </Directory>

to httpd.conf fixes the issue


In reply to Ajax and CGI problem by heatblazer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.