Parsing list of lists in jQuery
in Using jQuery
•
6 years ago
I have a list of lists (e.g. [[1,2],[3,4]]) passed from a Django view, stored in a hidden input of an html form, and submitted with jQuery. I need to parse that variable to pull indices. I have other lists passed between Django and html without a problem, but this list is posted by jQuery.
HTML:
<input type="hidden" name="resultMsgList" id="resultMsgList" value="[['View "S03_2005_TAZ_140813_160946_with_geom" was successfully created!', 'taz_mapfile_scen_tdm_140813_160946', 'S03_2005_TAZ_140813_160946_with_geom', 'C:/djangoProjects/web_output/mapfiles/ATLANTA/taz_mapfile_scen_tdm_140813_160946.map', [25, 50, 13.8926482138839, 44488.7998645071]]]"/>
Javascript:
var resultMsgList = $("#resultMsgList").val();
var data = {'resultMsgList':resultMsgList};
$.post(URL, data, function(result){
mapDataHtml = $(result).find("#mapData").html();
$("#mapData").html(mapDataHtml); });
I don't technically need the last 2 lines of code anymore, but it's not affecting my testing.
The
post data from jQuery output to the Google console is: resultMsgList
= u'[[\'View "S03_2010_TAZ_140813_112333_with_geom" was
successfully created!\', \'taz_mapfile_scen_tdm_140813_112333\',
\'S03_2010_TAZ_140813_112333_with_geom\',
\'C:/djangoProjects/web_output/mapfiles/ATLANTA/taz_mapfile_scen_tdm_140813_112333.map\',
[25, 50, 10.8820127624776, 49619.5163142776]]]'
It is currently giving me "String index out of range" and an error at
jquery-1.10.2.js:8706 so I think jQuery is viewing it as a string.
1