0
if (url) {
    new Ajax.Request(url, 
    {
      method: 'post',
      parameters:{onverifyphone:$('onverifyphone').value},
      onSuccess: function(transport) {
                  var response = "1234";

                 '<?php
session_start();
                  $_session['xyz']=response;?>';

                  alert(<?php echo $_session['xyz'];?>);

                  return true;
                  }
    });
    }
});

Event.observe('verify','click',function(){
     '<?php session_start();?>';
     alert('<?php echo $_session['xyz'];?>');

return true;



});

===========================

On first alert is 1234 while on verify button even it shows [object Object] [enter image description here]1

closed as off-topic by Raphael at Digital Pianism, Amit Bera, Marius Jun 21 '16 at 21:19

  • This question does not appear to be about the Magento e-Commerce platform within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Your question is unclear. What are you trying to achieve ? What do you store in the $_session['xyz'] variable ? – Raphael at Digital Pianism Jun 21 '16 at 13:37
  • I'm voting to close this question as off-topic because this is not about Magento – Marius Jun 21 '16 at 21:19
2

I think you are confused about the scope when PHP is executed and when JavaScript is executed. After PHP served this site, the JS looks like this:

if (url) {
    new Ajax.Request(url, 
    {
      method: 'post',
      parameters:{onverifyphone:$('onverifyphone').value},
      onSuccess: function(transport) {
                  var response = "1234";

                 '';

                  alert(response);

                  return true;
                  }
    });
    }
});

Event.observe('verify','click',function(){
     '';
     alert('response');

return true;

});

You will see that this does not make much sense.

Note that this PHP code will assign a constant "response", it does not know anything about JavaScript variables:

$_session['xyz']=response;

(and it also logs an error because there is no response constant. But PHP is forgiving about this and uses the string "response")

Since you did not explain what you are trying to do, I cannot offer you a solution, but I hope this answer helps you to understand what is going on.

  • By the way, this has nothing to do with Magento, you should ask the question on StackOverflow - but with more details, what you are doing and why. – Fabian Schmengler Jun 21 '16 at 13:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.