hello perl Gurus,

I have put the same question on stack exchange, but getting no response...
I am NOT able to send the cookie in response to AJAX call to my webpage.
I am following it exactly as the manual says, putting the cookie in the header 
of "$q", but it is not working :(the javascript code does not find any cookie 
in document.cookie

JSON response is being received and parsed just fine, below is simplified 
version of the script:

#!/usr/bin/perl

use strict;
use warnings;
use JSON::XS;
use Template;
use CGI::Simple;

my $q = new CGI::Simple;

my $ajaxResp = {} ;        #hashRef
my $ajaxResp_result;    #success, fail, error
my $ajaxResp_mesg;        #text mesg if needed
my $ajaxResp_obj;            #file,json array etc.
my $ajaxResp_type = 'text'; #text/html/json/file/newPage etc...

my $json = JSON::XS->new();


my ($checkAuthAjaxResp_result,$uid,$sid,$cookie)=checkAuth($q);  #external 
function working fine.  #good authentication.... at this point i have a well 
formed cookie hash.
    $ajaxResp_result = 'success';
    $ajaxResp_mesg = 'successful login.';
    $ajaxResp_type = 'text';
    $ajaxResp_obj = '';


# returns a JSAON ARRAY of: status = error/success, data=mesg, responseType, 
file=filename....
$ajaxResp->{'result'} = $ajaxResp_result;
$ajaxResp->{'responseType'} = $ajaxResp_type;
$ajaxResp->{'mesg'} = $ajaxResp_mesg;
$ajaxResp->{'obj'} = $ajaxResp_obj;

my $response = $json->encode ($ajaxResp);            # encode_json($ajaxResp);

# set STDOUT to auto-flush and print header
$| = 1;
if ((defined $checkAuthAjaxResp_result) && ($checkAuthAjaxResp_result eq 
'pass')){
        print $q->header(-type=>'application/json',
                        -cookie=>$cookie,
                        );
    }else {
        print $q->header(-type=>'application/json',
                        );
    }print $response;
1;



###############################  I also tried but this does not work. I am not 
seeing the cookie in the browser cookie table or on firebug log.
# set STDOUT to auto-flush and print header
$| = 1;
if ((defined $checkAuthAjaxResp_result) && ($checkAuthAjaxResp_result eq 
'pass')){print $q->header(-cookie=>$cookie)}
print "Content-type: application/json\n\n";
print $response;
1;



################## earlier it was ending like this: and this works fine:
# set STDOUT to auto-flush and print header
$| = 1;
print "Content-type: application/json\n\n";
print $response;
1;



another script which creates cookie as:my $cookie = $q->cookie( -name      => 
'mySID',
          -value     => $sid,
          -expires   => '+2m',
          -path      => '/cgi-bin/',
          -domain    => 'abc.com',
          -secure    => 1
         );



I am using TLS1.2 (SSL) for access.




pl also refer to: perl how to send cookie and json output via ajax response
  
|  
|   
|   
|   |    |

   |

  |
|  
|   |  
perl how to send cookie and json output via ajax response
 after a successful login/auth. my backend perl script has to send the 
generated cookie and a json response hash ...  |   |

  |

  |

 



Reply via email to