Reputation: 6086
I wish to encode an array of objects using JQuery.param() to then send the data via an ajax GET request.
The object is of type object and when doing console.log(JSON.stringify(obj)) i get:
[{"k":48.88975598812273,"B":2.362097778320276},{"k":48.88975598812273,"B":2.217902221679651},{"k":48.85023620829814,"B":2.217902221679651},{"k":48.85023620829814,"B":2.362097778320276},{"k":48.88975598812273,"B":2.362097778320276}]
When using JQuery.param(obj), it returns each value as undefined:
undefined=&undefined=&undefined=&undefined=&undefined=
I have read similar posts whereby an array of objects is incorrectly formed, however cannot see how this is malformed.
Can anyone advise?
Upvotes: 3
Views: 3713
Reputation: 124
As mentioned in the documentation for jQuery.param(), the array of objects must be in the specific format returned by .serializeArray().
jQuery.param() builds the parameter string using the "name" and "value" keys of each Object in the array. Your objects only have "k" and "B" keys, so they aren't serialized correctly.
Upvotes: 5