Page 1 of 1

jQuery/PHP: Passing lots of PHP data to JS

Posted: Wed Apr 27, 2011 8:47 am
by RCA86
Hi guys,

I posted a thread about a dynamic form, but my question was probably too big and vague, so I've narrowed it down.

I'll have a dynamic form with lots of checkboxes/radio buttons, to be used for choosing what options you want to buy. When you tick one box, jQuery will query the PHP file, which processes those options have been selected so far. Eg, you tick 'Box 1', and the price of 'Box 2' gets discounted.

So I want to find the cleanest way for PHP to return enough information through jQuery, so that the prices on the user form can all be updated. Does anybody have any suggestions? How would I go about returning a full JS array which I can then use to refresh all of the data?

Thanks!
Robert

Re: jQuery/PHP: Passing lots of PHP data to JS

Posted: Wed Apr 27, 2011 12:46 pm
by pickle
JSON.

with json_encode() you can create a native PHP array, encode it as JSON, then have jQuery parse it into a Javascript array.

Re: jQuery/PHP: Passing lots of PHP data to JS

Posted: Thu Apr 28, 2011 4:29 am
by RCA86
Thanks a bunch! Looked for a JSON tutorial, and that looks like it'll do the trick.

Cheers. :)