jQuery/PHP: Passing lots of PHP data to JS

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
RCA86
Forum Commoner
Posts: 32
Joined: Thu Mar 10, 2011 1:03 pm

jQuery/PHP: Passing lots of PHP data to JS

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
RCA86
Forum Commoner
Posts: 32
Joined: Thu Mar 10, 2011 1:03 pm

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

Post by RCA86 »

Thanks a bunch! Looked for a JSON tutorial, and that looks like it'll do the trick.

Cheers. :)
Post Reply