I would like to pass data from a dynamically built form via ajax to a php script, but have trouble finding the correct syntax for the parameter string format.
There’s a couple of fixed parameters and some are added dynamically, keys and values of the latter may change.
I’ve tried to build the parameter list as a concatenation of strings as below:
...
var dataVars = '{fctSelect: 2, strat: strat, ' + gbl.dataVariables + '}';
...
$j.ajax({
url: "ajax/script.php",
type: "POST",
data: dataVars,
...
gbl.dataVariables is formatted as follows : ‘field1: value1, field2: value2, field3, value3’
The resulting string to go into data “looks right” in console.log, but in the post tab of the console once the field validated, it appears like this:
{fctSelect: 2, strat: strat, ...
instead of:
fctSelect: 2
strat: 1
...
meaning that the parameters are not parsed. Could someone please point me to where I went wrong?
Darin Dimitrov’s solution is probably the way to go for you, I’ll just give you an alternative. If you collect your form’s fields and their values through serialize(), you can simply append your static data like this: