Any ideas if it is possible to serialize HTML fields which are in a multi-dimensional array format for transmission over AJAX post?
任何想法是否可以序列化多维数组格式的HTML字段,以便通过AJAX发布传输?
Tried serializeArray and that formats 1 level of the array.
尝试使用serializeArray并格式化数组的1级。
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.
使用serializeArray()可以正常工作
var formData = $('#createVacancy :input');
var serializedFormData = formData.serializeArray();
But some of the form data uses HTML array notation e.g.
但是一些表单数据使用HTML数组表示法,例如
name="tier[1][tiers][5][groupId]" value="5"
Result from serializeArray()
serializeArray()的结果
Normal name/value pairs comes through like Object { name="customer_name", value="Test customer name"}
正常的名称/值对来自Object {name =“customer_name”,value =“Test customer name”}
But fields which use html array notation come through like:
但是使用html数组符号的字段来自:
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.
虽然我需要将其分解为更多的对象。
2 个解决方案
#2
0
try JSON_decode http://us.php.net/manual/en/function.json-encode.php
尝试JSON_decode http://us.php.net/manual/en/function.json-encode.php
#1
#2
0
try JSON_decode http://us.php.net/manual/en/function.json-encode.php
尝试JSON_decode http://us.php.net/manual/en/function.json-encode.php