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

Friends of the path of Perl, I am trying to return JSON to javascript in Chrome from an IIS server using Activestate's PLX Perl. For those not familiar, Activestate plx is Perl as a DLL, so IIS can load it once and use it many.

I can get JSON return to work with a simple Perl CGI script

use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser); use JSON; my $c=CGI->new(); print $c->header('application/json'); my $json = JSON->new->relaxed->pretty; my $data = { this => 'test', is => 'simple'}; print $json->encode( $data );

That works fine as .pl using perl.exe. However when I change the extension to .plx, which IIS is configured to run with the perlis.dll, it still runs, but its return is seen as a string in the browser, not a JSON object. If I leave in the print headers, I get the content type in the string, if I remove it (ISAPI is not CGI) I still just get a string with the Json data.

Is anyone out there familiar with this 'technology' and able to give some guidance.

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!
  • Comment on I can not get JSON back from ActiveState plx ISAPI Perl running on IIS
  • Download Code

Replies are listed 'Best First'.
Re: Can not get JSON back from ActiveState plx ISAPI Perl, JSON and IIS
by Discipulus (Canon) on Feb 07, 2014 at 09:21 UTC
    Disclaimer: i'm not really an expert and this 'tecnology' is undebbaggable or worst... ;=) in any case..
    1- is this the correct output (the JSON object, with 'string' you mean a one line one?)?
    {
       "is" : "simple",
       "this" : "test"
    }
    

    2-what version of IIS are you using?
    3-have you modified the 'Web Server Extension' -> CGI part? if i modify this on a working IIS6 site running CGIs with perl.exe putting perliis.dll my site stops functioning.
    4-you yet know that this setup is a pain... is performance an issue? if you get something working keep it!

    hth
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      I am checking using the developer tools in Chrome. The first test gives me back a nice javascript object, I can browse it in the gui, but a bit hard to render here. The second just shows as a string, with or without content type header, depending on commenting that line in or out.

      $.post('/cgi-bin/cp_json_test.pl', {},function (data) {console.dir(dat +a) } ); > Object {readyState: 1, getResponseHeader: function, getAllResponseHe +aders: function, setRequestHeader: function, overrideMimeType: functi +on…} > Object $.post('/cgi-bin/cp_json_test.plx', {},function (data) {console.dir(da +ta) } ); > Object {readyState: 1, getResponseHeader: function, getAllResponseHe +aders: function, setRequestHeader: function, overrideMimeType: functi +on…} > Content-Type: application/json; charset=ISO-8859-1 {"is":"simple","t +his":"test"}

      IIS is version 6. I am so sorry about that :-(

      I have .pl exgtensions running with perl.exe and .plx with perlis.dll

      The reason I am trying to do this is mostly performance, and the challenge :-) I may give up though and return to plain perl.exe. I thought it looked like a nice way to get a bit more kick out of a heavily loaded server.

      Cheers,
      R.

      Pereant, qui ante nos nostra dixerunt!

        I am checking using the developer tools in Chrome.

        Try checking using lwp-request -UusSeE http... :)

Re: ActiveState plx ISAPI Perl, JSON and IIS (PerlEx)
by Anonymous Monk on Feb 07, 2014 at 09:08 UTC