I'm attempting to step foot into the web development world, and I'm having some trouble understanding why my basic hello world script is failing. I have a simple AJAX call to a python cgi script that returns a small bit of HTML, but instead the call fails and I get "Internal Server Error" as the error message. Here's my code:
Python script:
#!/usr/local/bin/python
print "Content-Type: text/html\n"
print """\
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
"""
AJAX Call:
$(function(){
$('#clickme').click(function(){
$.ajax({
url: "cgi-bin/ajaxpost.cgi",
dataType: "html",
type: "POST",
success: function(response){
alert(response);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
});
});
And here's what my server error logs says:
CGI ERROR: A system problem prevented your request from being completed., referer: [my test page]
Premature end of script headers: ajaxpost.cgi, referer: [my test page]
I double checked with my server and "#!/usr/local/bin/python" is the correct path to python. Additionally, they say they don't have a designated cgi-bin folder, any cgi can run from any folder as long as it has a .cgi extension. EDIT: Also, I have allowed the .cgi to be executed on the server.
I'll go ahead and admit I'm probably going to need an "explain it like I'm five" answer. Thanks!
print
- try it again after truncating it. – thkang