Passing a dict of dict with Ajax
<p>I'm working on a website running on Django.
I need to pass data from the Javascript to my Python code with Ajax.</p>

<p>Here's my code:</p>

<pre><code>// Javascript file
   function myFunc() {
        {...} // Generate var 'values' which is a dict of dict {{},{}...}
        console.log(JSON.stringify(values));
        $.ajax({
                url : "holt/",
                type : "POST",
                data : values,
                success : function (json) {
                   console.log(json)
                },
                error : function () {
                    alert("Error Ajax");
                }
            })
    }
</code></pre>

<p>My view in python:</p>

<pre><code>  class getHolt(TemplateView):
        def get(self, request, *args, **kwargd):
            pass 
        def post(self, request, *args, **kwargd):
            if request.user.is_authenticated():
                data = dict(request.POST)
                h = Holt(data)
                response_data, success = h.get_holt(2021, no_freeze=True)
                return HttpResponse(
                    json.dumps(response_data),
                    content_type="application/json"
                )
</code></pre>

<p>However when I run this, with:</p>

<blockquote>
  <p>Javascript values</p>
</blockquote>

<pre><code>values= {
    "1":{"data_2013":"49105","data_2014":"92620","data_2015":"30000","data_2016":"1945000"},
    "2":{"data_2013":"2885906","data_2014":"2876120","data_2015":"2882653","data_2016":"2787520"},
    "3":{"data_2013":"29201124","data_2014":"29470635","data_2015":"29383195","data_2016":"30154361"}}
</code></pre>

<p>I receive this in my Python code:</p>

<pre><code>print request.POST
</code></pre>

<blockquote>
  <p>&lt; QueryDict: {u'1[data_2014]': [u'92620'], u'1[data_2015]':
  [u'30000'], u'3[data_2013]': [u'29201124'], u'3[data_2014]':
  [u'29470635'],...}></p>
</blockquote>

<pre><code>print dict(request.POST)
</code></pre>

<blockquote>
  <p>{u'1[data_2014]': [u'92620'], u'1[data_2015]':
  [u'30000'], u'3[data_2013]': [u'29201124'], u'3[data_2014]':
  [u'29470635'],...}</p>
</blockquote>

<p>Why don't I receive a dict of dict like I've send ?</p>

<p>What does Ajax do to the data before "sending" them ?</p>

<p>Thank You</p>

<p>JS dictionnary</p>

<pre><code>console.log(JSON.stringify(values));
   {"1":{"data_2013":"49105","data_2014":"92620","data_2015":"30000","data_2016":"1945000"},"2":{"data_2013":"2885906","data_2014":"2876120","data_2015":"2882653","data_2016":"2787520"},"3":{"data_2013":"29201124","data_2014":"29470635","data_2015":"29383195","data_2016":"30154361"}}
</code></pre>