Two things:
You can't just dump JSON on the end of a URL and expect it to go through to the server correctly.
At the very least, you have to URI-encode it:
url += "&json="+encodeURIComponent(json);
The way you're using
extraFields
in your code snippet, it is not being used as an array. If you've created it as an array, those keys will not be serialized. The way you're using it, the correct way to createextraFields
is:extraFields = {}; // NOT `= []` and NOT `= new Array()`
That's an object, not an array. (Don't let the PHP term "associative array" fool you; that term is fairly PHP-specific and not related to the term "array" in the general sense. If you want arbitrary name/value pairs in JavaScript code, the term is "object" [or sometimes "map" or "dictionary", but they're objects].)
If you add non-index properties to an array,
JSON.serialize
will ignore them (leave them out). Only use arrays ([]
) with JSON for numerically-indexed data. Using objects ({}
) for name/value pairs.