Is it possible to submit nested objects in jQuery?
Hi all,
I've been banging my head on a wall with this problem and I think it's come down to whether or not jQuery can do something for me.
I am attempting to save what we call a template. This template is made up of sections. Each section has a series of elements, including an array called children, which contains child sections.
The following json is an example of a template (in reality, a template is made up of over 80 of these sections):
- {
"autotextId": 0,
"canBeNull": "N",
"children": [
{
"autotextId": 0,
"canBeNull": "N",
"children": [],
"displayHeader": "N",
"editable": "Y",
"formatType": "Assessment",
"helpText": "This is some <b>HTML<\/b> text.",
"outlineSpecific": "N",
"parentId": 274,
"parentSectionId": 274,
"requiresQa": "Y",
"sectionId": 275,
"sectionSectionId": 281,
"sectionSeqNumber": 1,
"sectionSourceUrl": null,
"templateId": 101
}
],
"displayHeader": "Y",
"editable": "N",
"formatType": "Text",
"helpText": null,
"outlineSpecific": "N",
"parentId": 200,
"parentSectionId": 200,
"requiresQa": "N",
"sectionId": 274,
"sectionSectionId": 280,
"sectionSeqNumber": 8,
"sectionSourceUrl": "Header",
"templateId": 101
}
In attempting to save this with a POST via jQuery.ajax(), I am unable to get any data below the first level.
The result I get is this (printed out on my Java servlet side, which handles the http request):
- [autotextId] = [0]
[sectionSourceUrl] = [Header]
[children] = [[object Object]]
[entityURL] = [http://localhost:8090/direct/msi-template/101]
[sectionSectionId] = [200]
[entityReference] = [/msi-template/101]
[displayHeader] = [N]
[parentSectionId] = [0]
[sectionId] = [200]
[helpText] = [Blah blah blah!]
[no-cache] = [true]
[templateId] = [101]
[editable] = [N]
[parentId] = [0]
[entityId] = [101]
[sectionSeqNumber] = [1]
[formatType] = [Text]
[requiresQa] = [N]
[outlineSpecific] = [N]
[canBeNull] = [N]
You can see how the children parameter shows '[object Object]'. For some reason, jQuery is parsing the array of children elements as an array of strings (when the object is further interrogated) and each string says '[object Object]'.
Is there a way to submit this nested object-style of json in jQuery and if so, how?
I have read that you can submit an XML document, but this would be an option of very last resort if possible.
Any help would be greatly appreciated.