Please bear up with me, I'm new to PHP. I'm using a mixture of PHP
and jQuery
on the same page. I need to pass variables from jQuery
to PHP
. All examples I came across describe how to pass variables to a PHP
file on the server which I don't want. So far I manged to convert object to JSON using jQuery $.toJSON();
My question is: is it possible to pass jQuery data to php code if both jQuery
and PHP
reside on the same page?
Here is my code so far:
var myObject = {name: 'Tomas', age: 38};
var encoded = $.toJSON( myObject);
var name = $.evalJSON( encoded ).name;
var version = $.evalJSON(encoded).age;