I'm passing a 2-dimensional array of float values to my views.py via ajax. My ajax call looks like this:
$.ajax({
method: "POST",
url: "introURL",
data: {
csrfmiddlewaretoken: document.getElementsByName('csrfmiddlewaretoken')[0].value,
dsg_mtx : JSON.stringify(dsg_mtx),
},
success: function(data) {
document.getElementById("test").innerHTML = data; // echo response
},
error: function() {
alert ("Something went wrong");
}
I'm pulling my data to the view with this call:
def introURL(request):
if request.is_ajax():
try:
designMtx = json.loads(request.POST['dsg_mtx'], parse_float=None)
except KeyError:
return HttpResponse('Error, intro import')
... Some transformation of designMtx...
return HttpResponse(response)
else:
raise Http404
so my question is how do I convert this json stringify'd object back to a 2-dimensional array which I can use to compute a response? As you can see I tried using the parse_float option, but it's still a str data type.
the array being passed, dsg_mtx, is created with a Handson tables and looks like this:
-1 -1
-1 1
1 -1
1 1
Thanks for your guidance.
dsg_mtx$.ajaxaddconsole.log(dsg_mtx)and show what is in console. In the same way in Python code beforejson.loadsaddprint request.POST['dsg_mtx']and show whats is in output.