title: Django Ajax 'GET'
body: <p>newbie here. I am trying to get some data from my database using ajax.</p>
  
  <p>In my views.py,</p>
  
  <pre><code>def getEvents(request):
      eventList = Events.objects.all()
      events=[]
      for event in eventList:
          events.append({"name": event.name, "start": event.start, "end": event.end})
      return HttpResponse(events, content_type="application/json")
  </code></pre>
  
  <p>Note that <code>Events</code> is the <code>model</code> that I am trying to parse. After I collect the data from this model, I want to return it to my template using the following ajax code:</p>
  
  <pre><code>            $.ajax({
                  url: 'getEvents/',
                  datatype: 'json',
                  type: 'GET',
                  sucess: function(data) {
                      alert(data.name);
                  }
              });
  </code></pre>
  
  <p>In my urls.py:</p>
  
  <pre><code>url(r'^getEvents/', views.getEvents, name='getEvents'),
  </code></pre>
  
  <p>However, I think I am doing something wrong because it doesn't work. I have been stuck on this for hours...Any ideas?</p>
  
  <p>EDIT:</p>
  
  <p>Okay. When I append the <code>getEvents</code> to the url, I do see all the database objects together in a dict but it seems my <code>ajax</code> is not working. How do I parse this data? The data is in the form:</p>
  
  <pre><code>[{"start": "2017-02-06", "end": "2017-02-07", "name": "Capstone Meeting"},
  {"start": "2017-02-07T0:00", "end": "2017-02-08", "name": "Capstone"}, 
  {"start": "2017-01-31T0:00", "end": "2017-02-01", "name": "dasdsd"}, 
  {"start": "2017-01-31", "end": "2017-02-01", "name": "hjb"}]
  </code></pre>
  
  <p>Here is what I have so far...</p>
  
  <pre><code>            $.ajax({
                  url: 'getEvents/',
                  datatype: 'json',
                  type: 'GET',
                  sucess: function(data) {
                      $.each(data, function(index, element) {
                          $('body').append($('&lt;div&gt;', {
                              text: element.name
                          }));
                      });
                  }
              });
  </code></pre>