228 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has collected 100+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
stevebluck says

Hi everyone,

I’m trying to pass js obects to php via jQuery’s .load() function.

Everything is working fine but I don’t know or understand how to output the obect using php.

Here is my JS code:

jQuery(function () {

    var myArray = [{ 'name' : 'Steve', 'surname' : 'Bluck' }];

    //Save options via Ajax-------------//
    jQuery("#saveoptions").click(function(){

             jQuery(this).load('<?php bloginfo('template_directory'); ?>/lib/admin/save.php', {

                'options[]' : myArray

               });

          });

});

This is my PHP code:

$options = $_POST['options'];
print_r($options);

And the outcome is this:

Array ( [0] => [object Object] )

What am I doing wrong?

81 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
Fynn says

Maybe you should check out the PHP functions json_encode and json_decode?

Edit: I was looking for a tut that handles AJAX interaction with PHP with the avove mentioned functions but I can’t find it anymore.

If you’re still having difficulties I can send you my js and php script that does this kind of interaction, let me know :) I think the scripts are pretty self-explanatory.

228 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has collected 100+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
stevebluck says
Maybe you should check out the PHP functions json_encode and json_decode?

Edit: I was looking for a tut that handles AJAX interaction with PHP with the avove mentioned functions but I can’t find it anymore.

If you’re still having difficulties I can send you my js and php script that does this kind of interaction, let me know :) I think the scripts are pretty self-explanatory.

Yes please, I’m going crazy – I’ll send you a mail now.

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by