0

Any ideas if it is possible to serialize HTML fields which are in a multi-dimensional array format for transmission over AJAX post?

Tried serializeArray and that formats 1 level of the array.

Data I need to serialize would be a series of name/value fields e.g.

name="customer" value="the value"
name="location" value="the location"

Using serializeArray() works fine on these e.g.

var formData = $('#createVacancy :input');
var serializedFormData = formData.serializeArray();

But some of the form data uses HTML array notation e.g.

name="tier[1][tiers][5][groupId]" value="5"

Result from serializeArray()

Normal name/value pairs comes through like Object { name="customer_name", value="Test customer name"}

But fields which use html array notation come through like:

Object { name="tier[1][publication_date]", value="03 Feb 2011"}, 
Object { name="tier[1][publication_date_db]", value="2011-02-03"}, 
Object { name="tier[1][tiers][5][groupId]", value="5"}, 
Object { name="tier[1][tiers][5][groupName]", value="Diamond"}

I'd have though this would need to be broken down into further objects.

3
  • can you example what you want to serialize Commented Feb 3, 2011 at 15:06
  • What is the reason for herarchy in field names ? Is it your HTML structure, how you want to be passes - Is it all tiers # needed ? Commented Feb 3, 2011 at 15:42
  • The hierarchy is dynamically generated with jQuery so to keep a logical order when submitting the form I use the html structure above. Commented Feb 3, 2011 at 16:14

2 Answers 2

1

Try using the JSON.stringify method from json2.js.

Sign up to request clarification or add additional context in comments.

Comments

0

try JSON_decode http://us.php.net/manual/en/function.json-encode.php

2 Comments

It's prior to the Ajax call I need this. In essence I need to obtain all form fields and formulate a Json string for transmission to a Php file where I will then use Json_decode.
show example of "HTML fields which are in a multi-dimensional array"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.