http://www.perlmonks.org?node_id=975415


in reply to Re: perl cgi server response issue or not?
in thread perl cgi server response issue or not?

Well, good point but no, everything seems to be OK, the only problem is that perl`s script output does not display into the browser. That is strange since I`ve tested direct form validation without JS and it is working ok... But here it`s fishy...

Replies are listed 'Best First'.
Re^3: perl cgi server response issue or not?
by Anonymous Monk on Jun 10, 2012 at 12:24 UTC

    Well, good point but no, everything seems to be OK, the only problem is that perl`s script output does not display into the browser. That is strange since I`ve tested direct form validation without JS and it is working ok... But here it`s fishy...

    Maybe you should figure out why? something something http headers

Re^3: perl cgi server response issue or not?
by aaron_baugher (Curate) on Jun 11, 2012 at 01:49 UTC

    When you call the open() and send() methods on your URL, that does the request, but you never do anything with the data your server returns. Look into the properties responseText and responseXML to get at your data. You'll also need to use the onreadystatechange event to know when the data is ready for use.

    Or you could replace the entire Javascript portion with a few lines of jQuery. It takes a lot less typing to get and change the values of elements, and the ajax routines (here using get) provide callbacks that will be fired when the data is ready (or under other conditions you may want to catch). You also don't have to construct a query string for your URL, and worry about what happens if people put unexpected characters in the fields.

    $(document).ready(function() { $("#submit").click(function(e) { e.preventDefault(); // don't let browser submit var name = $('#name').val(); var age = $('#age' ).val(); if( name && age ){ $.get(url, { name: name, age: age }, function(data){ $('#somediv').html(data); // replace div contents with new + data }); } else { alert('Missing form fields!); } }); });

    Aaron B.
    Available for small or large Perl jobs; see my home node.