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.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |