228 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
  • United Kingdom
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
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
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
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
  • United Kingdom
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.

by
by
by
by
by
by