0

I am trying to print js variable but it shows only String

success: function(data) 
            {
               var temp = $(".acname").text(data.accName[0].user_full_name); 
            },
         buttons: [
                    {
                extend: 'print',footer: 'true',className: "btn btn-primary",
                customize: function ( win ) {
                $(win.document.body)
                  .css( 'font-size', '10pt' )
                  .prepend(
                '<h2 align="center"><font color="#5CAAFF">Barque Trans And Logistics P.V.T.L.T.D</font></h2>'+
                 '<h3 align="center"><font color="#5CAAFF">Safeguarding Valuables</font></h3>'+
                  '<hr style="height: 1px;">'+
                  '<h5 align="center"><strong>REPORT FOR LEDGER </strong></h5>'+
              //on this line I am trying to use variable    
          '<h5 align="center"> <?php echo $temp ?> </h5>'
                       );

In my var temp variable it gives me name and want that name on

  `'<h5 align="center"> <?php echo $temp ?> </h5>'`
Aksen P
  • 4,564
  • 3
  • 14
  • 27
farhantechno
  • 595
  • 6
  • 15
  • PHP logic runs on the server. JS logic runs on the client, long after any server logic has completed and sent the response text to the client. As such the two cannot directly interact as you're attempting. One solution would be to use AJAX to send a value from JS to PHP, but this is a completely different pattern to what you currently have. I'd suggest researching it - see the second duplicate linked above. – Rory McCrossan Jun 21 '19 at 12:39
  • 1
    With all that said, in this example you don't need PHP at all. Just concatenate the JS variable with the string: `'
    ' + temp + '
    '`. You just need to make sure `temp` is declared within scope of both locations where it's used
    – Rory McCrossan Jun 21 '19 at 12:40
  • You have got PHP script inside a JS callback function. PHP cannot run inside JS. PHP executes in server side and JS runs on your browser. Can you please elaborate what you're trying to do? – jim1427 Jun 21 '19 at 12:42
  • @RoryMcCrossan i am try this `'
    ' + temp + '
    '` code but it gives me `object object` output
    – farhantechno Jun 21 '19 at 12:53
  • That's because `temp` holds a jQuery object. – Rory McCrossan Jun 21 '19 at 13:01
  • @RoryMcCrossan I run with this code`document.cookie="templedger="+data.accName[0].user_full_name; ` `'
    '+ "" +'
    '`
    – farhantechno Jun 21 '19 at 13:03

0 Answers0