tags:

views:

29

answers:

1

I have a large form (30 different input fields) and want to use jQuery's ajax functionality to POST it to a PHP script.

For smaller forms I usually send each variable as it's own POST variable. e.g.

$.ajax({
  type: 'POST',
  url: 'someScript.php',
  data: {var1: var1, var2: var2, etc: etc}
});

Is there any disadvantage of using this method when sending so many variables? Does it use more memory etc?

(The alternative being to send the data as one array and process it back into individual variables in the PHP script).

Thanks!

+2  A: 

The data does take up more space, but that shouldn't be too much of an issue. One place where you can improve is:

Instead of doing:

data: {var1: var1, var2: var2, etc: etc}

You can do:

data: jQuery("#myForm").serialize()

Which serializes the form for you.

Vivin Paliath
Thanks for your reply and the extra information about serialize!
Matt