passing PHP objects to javascript [duplicate]

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:

  1. Convert the PHP object to an array.

  2. Using json_encode() to encode that PHP array.

  3. Pass JSON-encoded data to PHP

  4. Decode JSON from JavaScript using JSON.parse or you can use jQuery.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.

Leave a Comment