I would like to know what would be the best practice to perform this:
-
Based on a selection, create a list of “selected items” which would be a list of this kind:
{items {categoryString {tag_id1 {[fr]=>itemFR, [en]=>itemEN} {categoryString {tag_id2 {[fr]=>item2FR, [en]=>item2EN} {categoryString2 {tag_id3 {[fr]=>item3FR, [en]=>item3EN} } -
Send this information to my server script when sending my form (not through javascript but normal post form).
- Parse the received information on my server script (PHP).
Point 1 is done like this:
function initTagArray(listSelector) {
var et_tag_list = new Object();
var cat = "CATDEF";
et_tag_list[cat] = new Object();
listSelector.each(function() {
et_tag_list[cat][$(this).val()] = [];
et_tag_list[cat][$(this).val()]['fr'] = [$(this).text()];
et_tag_list[cat][$(this).val()]['en'] = [$(this).text()];
});
return et_tag_list;
}
Point 2: I was thinking about storing that information in JSON array, but not sure how… By parsing my object/array and manually creating the json array?
Point 3: If Json array is sent it will be easy to parse it.
I’m looking here for the best practices on how to do this the most clean way as possible.
Use json stringified object/data that is either parsed as follows:
you can look for these links for implementation etc:
check question
text on this link: json object accessingJSON in JavaScript
JSON.Stringify
pass json object to array – autocomplete
Create a JSON serialized object to make a $.postJSON call