I have a dynamically generated form that I would like to submit using Ajax. The form contains some input fields and some checkboxes - so the tot开发者_如何学Cal number of checkboxes that will be submitted is obviously unknown at the start. By "dynamically generated" I mean the contents and the id's of the form elements are pulled from a DB and again, I never know how many there will be in advance.
From what I understand, to submit it with Ajax I need to execute something like this in my javascript function:
xmlhttp.open("GET","/incl/myfile.php?var[]=a&var[]=b&...", true);
My problem is generating those "var[]=a&var[]=b&..." lists. Particularly, I have a hard time understanding how to generate it for those checkboxes, which may or may not be checked.
Is there something that will capture the entire content of the form input fields and format it into a nice GET url query? A plugin perhaps? Something in JQuery maybe?
Yes, take a look at jQuery's serialize method. http://api.jquery.com/serialize/
You want jQuery's .serialize() method.
精彩评论