You can convert the PHP object to an array, and then use JSON function to encode it. After that, decode it from JavaScript. Here are some basic steps:
-
Convert the PHP object to an array.
-
Using
json_encode()
to encode that PHP array. -
Pass JSON-encoded data to PHP
-
Decode JSON from JavaScript using
JSON.parse
or you can usejQuery.parseJSON
to do that.
This is an interesting tutorial about passing a JavaScript object to a PHP object. You might find it useful by watching some other featured/related videos.
Hope this helps.