I am trying to run an ajax $.post call on a script that builds a form dynamically. How would i go about doing this. Currently the psudocode looks like this:
//I Would build the ajaxString with a foreach loop, looping through all of the inputs on //the page. The following is psudocode,
var ajaxString; for each inputs { ajaxstring += "field i: \"\" + $(\"#frame\").contents().find(\":input:eq(i)\").val() +\"\"";
} $.post("dynamicScript.php",{ "" + ajaxString + ""
//Right now this is how it works normally //field 1: "" + $("#frame").contents().find(":input:eq(0)").val() +"", //f开发者_运维百科ield 2: "" + $("#frame").contents().find(":input:eq(1)").val() +"", //field 3: "" + $("#frame").contents().find(":input:eq(2)").val() +"", //field 4_check: "" + $("#frame").contents().find(":input:eq(3)").val() +"" },function(data) {
I figured it out, using the serialize function. here is the code
$.post("dynamicScript.php", $("#frame").contents().find("#SubmitForm").serialize(), function(data) { });
I would take a look at the jquery method called serialize. It will return a query string of all the inputs in the form.
e.g. (a=1&b=2&c=foo)
精彩评论