Best practice for sending large number of variables using jQuery ajax
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 开发者_Go百科send the data as one array and process it back into individual variables in the PHP script).
Thanks!
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.
精彩评论