in reply to Perl's CGI.pm and Javascript's XMLHttpRequest (SOLVED)

Did you set a content-type header for your POST request? Try adding this before you call send():

xmlhttp.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );

Also, I strongly recommend checking out something like prototype.js -- it makes doing cross-platform AJAX requests much easier than dealing with XMLHTTPRequest directly.

Replies are listed 'Best First'.
Re^2: Perl's CGI.pm and Javascript's XMLHttpRequest
by chargrill (Parson) on Dec 06, 2006 at 21:50 UTC

    Straying a little more off topic...

    I'll second the recommendation of using something like prototype.js for this. Your xmlHTTPRequest will look like this:

    new Ajax.Request( '/url/to/post/to', { asynchronous: true, evalScripts: true, parameters: Form.serialize(this), onComplete: jsFunctionToCallBack });

    If you're using Catalyst (ah, back to perl!) there's even a handy Prototype plugin to make things a little easier.

    Recently, though, I've been turned onto jquery which is a little more lightweight than prototype, and much better documented. The above post would then look something like:

    $.ajax( { url: '/url/to/post/to', type: 'POST', dataType: 'html', data: $('form#form_id').formSerialize(), complete: jsFunctionToCallBack } );


    --chargrill
    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)