Hello Rajeev, your code exhibits many bad elements, and you don't seem to apply all the advice I've been giving you. Please go over http://perl-begin.org/tutorials/bad-elements/ , read it and internalise it.
Furthermore, the E-mail headers of your message are obnoxious with a From: of the list and a reply-to to your personal Yahoo account. That may be a Yahoo mishap so please consider avoiding using Yahoo when posting to mailing lists. On Sun, 12 Jun 2016 21:23:49 +0000 (UTC) Rajeev Prasad via beginners <beginners@perl.org> wrote: > 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 > Are you sure it should be in document.cookie rather than the AJAX's request cookie? Can you try listening on the wire using wireshark or whatever? Regards, Shlomi Fish > 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 ... | | > > | > > | > > > > > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/