beckmanel has asked for the wisdom of the Perl Monks concerning the following question:

I'm using CGI::Application::Dispatch on the Perl backend

Data is sent from Javascript:

88 var _factories = [ 89 function() { return new XMLHttpRequest(); }, 90 function() { return new ActiveXObject("Msxml2.XMLHTTP"); } +, 91 function() { return new ActiveXObject("Microsoft.XMLHTTP") +; } 92 ]; 93 94 var _factory = null; 95 96 function newRequest() { 97 if (_factory != null) return _factory(); 98 99 for(var i = 0; i < _factories.length; i++) { 100 try { 101 var factory = _factories[i]; 102 var request = factory(); 103 if (request != null) { 104 _factory = factory; 105 return request; 106 } 107 } 108 catch(e) { 109 continue; 110 } 111 } 112 _factory = function() { 113 throw new Error("XMLHttpRequest not supported"); 114 } 115 _factory(); 116 } 1233 var http_request; 1234 http_request = newRequest(); 1252 var query = "ip=" + document.getElementById('ip').value; 1253 http_request.open('POST', "/index.pl/get_neigh_display", t +rue); 1254 http_request.send(query); 1255 return false;

But when I do the same action from the same web page, but different browsers, I get parameters in a different form through Perl CGI (see below). My code has been working with the IE form, can I do anything to make the Firefox output form similar ?

THANKS Much in advance.

The below was generated in the target Perl procedure by:

print STDERR "QUERY: ", Dumper($self->query), "\n";

FIREFOX 15202 [Tue Jul 22 08:55:55 2014] [error] [client 56.80.2.131] QUERY: + $VAR1 = bless( {, referer: http://56.207.201.210:8083/ 15203 [Tue Jul 22 08:55:55 2014] [error] [client 56.80.2.131] + '.parameters' => [, referer: http://56.207.201.210:8083/ 15204 [Tue Jul 22 08:55:55 2014] [error] [client 56.80.2.131] + 'POSTDATA', referer: http://56.207.201. +210:8083/ 15205 [Tue Jul 22 08:55:55 2014] [error] [client 56.80.2.131] + ],, referer: http://56.207.201.210:8083/ 15206 [Tue Jul 22 08:55:55 2014] [error] [client 56.80.2.131] + '.charset' => 'ISO-8859-1',, referer: http://56.207.201.21 +0:8083/ 15207 [Tue Jul 22 08:55:55 2014] [error] [client 56.80.2.131] + 'POSTDATA' => [, referer: http://56.207.201.210:8083/ 15208 [Tue Jul 22 08:55:55 2014] [error] [client 56.80.2.131] + 'ip=56.97.243.16', referer: http://56.207. +201.210:8083/ 15209 [Tue Jul 22 08:55:55 2014] [error] [client 56.80.2.131] + ],, referer: http://56.207.201.210:8083/ 15210 [Tue Jul 22 08:55:55 2014] [error] [client 56.80.2.131] + '.fieldnames' => {},, referer: http://56.207.201.210:8083/ 15211 [Tue Jul 22 08:55:55 2014] [error] [client 56.80.2.131] + 'escape' => 1, referer: http://56.207.201.210:8083/ 15212 [Tue Jul 22 08:55:55 2014] [error] [client 56.80.2.131] + }, 'CGI' );, referer: http://56.207.201.210:8083/ 15213 [Tue Jul 22 08:55:55 2014] [error] [client 56.80.2.131] , refe +rer: http://56.207.201.210:8083/ 15214 [Tue Jul 22 08:55:55 2014] [error] [client 56.80.2.131] [Tue J +ul 22 08:55:55 2014] index.pl: Use of uninitialized value in pattern +match (m//) at /var/www/smartncm_test_ie11/lib/OpenNCMApp/EntryPoint. +pm line 896., referer: http://56.207.201.210:8083/ 15215 [Tue Jul 22 08:55:55 2014] [error] [client 56.80.2.131] [Tue J +ul 22 08:55:55 2014] index.pl: Use of uninitialized value in pattern +match (m//) at /var/www/smartncm_test_ie11/lib/OpenNCMApp/EntryPoint. +pm line 897., referer: http://56.207.201.210:8083/ IE 15332 [Tue Jul 22 08:58:58 2014] [error] [client 56.80.2.131] QUERY: + $VAR1 = bless( {, referer: http://56.207.201.210:8083/# 15333 [Tue Jul 22 08:58:58 2014] [error] [client 56.80.2.131] + '.parameters' => [, referer: http://56.207.201.210:8083/# 15334 [Tue Jul 22 08:58:58 2014] [error] [client 56.80.2.131] + 'ip', referer: http://56.207.201.210:80 +83/# 15335 [Tue Jul 22 08:58:58 2014] [error] [client 56.80.2.131] + ],, referer: http://56.207.201.210:8083/# 15336 [Tue Jul 22 08:58:58 2014] [error] [client 56.80.2.131] + '.charset' => 'ISO-8859-1',, referer: http://56.207.201.21 +0:8083/# 15337 [Tue Jul 22 08:58:58 2014] [error] [client 56.80.2.131] + 'ip' => [, referer: http://56.207.201.210:8083/# 15338 [Tue Jul 22 08:58:58 2014] [error] [client 56.80.2.131] + '56.97.243.16', referer: http://56.207.201.210:8 +083/# 15339 [Tue Jul 22 08:58:58 2014] [error] [client 56.80.2.131] + ],, referer: http://56.207.201.210:8083/# 15340 [Tue Jul 22 08:58:58 2014] [error] [client 56.80.2.131] + '.fieldnames' => {},, referer: http://56.207.201.210:8083/ +# 15341 [Tue Jul 22 08:58:58 2014] [error] [client 56.80.2.131] + 'escape' => 1, referer: http://56.207.201.210:8083/# 15342 [Tue Jul 22 08:58:58 2014] [error] [client 56.80.2.131] + }, 'CGI' );, referer: http://56.207.201.210:8083/# 15343 [Tue Jul 22 08:58:58 2014] [error] [client 56.80.2.131] , refe +rer: http://56.207.201.210:8083/#

Replies are listed 'Best First'.
Re: Firefox/Javascript/Perl CGI argument passing issue
by Corion (Patriarch) on Jul 22, 2014 at 14:55 UTC

    Perl only runs on the backend. Your Javascript runs on the frontend ("The Browser"). Your issue is that IE has Msxml2.XMLHTTP and Microsoft.XMLHTTP while Firefox does not.

    Perl cannot help here, as this is a compatibility issue between Firefox and IE.

Re: Firefox/Javascript/Perl CGI argument passing issue
by marto (Cardinal) on Jul 22, 2014 at 15:12 UTC

    Not a perl issue, don't write JavaScript that only works in IE. You could consider using the jQuery framework to do all the heavy lifting for you.

      Indeed.   Even though these JS libraries have become Phat and Heavy, they are specifically designed to “abstract away” the numerous browser- and browser-version specific bits, like this very one.   jQuery is the dominant one out there right now, but it’s not the only one.   Some, such as Prototype.js, are quite a bit smaller. (I humbly stand corrected ...)   However, the bottom line is ... don’t even try to ride this pony bareback.   Use a saddle.

        Some, such as Prototype.js, are quite a bit smaller.

        Without qualifying that statement to discuss UI libs or something, it’s not right; Prototype is almost exactly twice as big as jQuery. And FWIW Prototype is near the end of the list I’d recommend due to the richness of other kits and its history of screwing up built-ins and not playing well with other kits.

        ~/>wget "http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min +.js" ~/>wget "http://ajax.googleapis.com/ajax/libs/prototype/1.7.2.0/protot +ype.js" ~/>sl prototype.js jquery.min.js -rw-rw-r-- 1 moo staff 95786 May 12 19:26 jquery.min.js -rw-rw-r-- 1 moo staff 197777 Apr 23 01:11 prototype.js
Re: Firefox/Javascript/Perl CGI argument passing issue
by perlfan (Parson) on Jul 22, 2014 at 16:27 UTC
    I use CGI::Application::Dispatch quite heavily, and my workflow generally includes fleshing out the request handling and responses using something like the Chrome's REST Console.

    Once I have that fleshed out, I like to us YUI 3 (specifically Y.IO) to build out one of many possible client interfaces.

    The important message here is the workflow. The tools mentioned are what I use, but you can use anything. It's best to work out the REST API first, without the UI being built up along side. Once you get the API and build up your first (of many) REST consuming clients, then you might have to slightly adjust your API if done right, but you don't want to be molding your hopefully long lived REST API with what will be a relatively much shorter lived client.

Re: Firefox/Javascript/Perl CGI argument passing issue
by tangent (Parson) on Jul 22, 2014 at 17:03 UTC
    Try changing your Javascript so that it sets the MIME type of the request:
    http_request.open('POST', "/index.pl/get_neigh_display", true); http_request.setRequestHeader('Content-Type', 'application/x-www-form- +urlencoded'); http_request.send(query);