title: Getting data back from django views.py and using ajax to display it
body: <p><strong>EDITED</strong></p>
  
  <p>I'm trying to use jquery/ajax to display data returned from a django method.</p>
  
  <p>I have a html button called keywordBtn. So when it's pressed, the updateKeywordSubscribed method will be called. </p>
  
  <p>however, my object is not being returned by django. Is there something wrong with my method?</p>
  
  <p>If successful, the div section name "update" would display the list of words in that json list.</p>
  
  <p>what i have in my html:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          $(document).ready(function() { 
              $("#keywordBtn").click(function(e) { 
                  updateKeywordSubscribed(e, "#keywords"); 
              });
          });
          function updateKeywordSubscribed(e, keywords) {
              e.preventDefault();
              var option_form = jQuery(e.target);
              $.ajax({
                  url : option_form.attr('action'),
                  type : option_form.attr('method'),
                  data : option_form.serialize(),
                  dataType : 'json',
                  success : function(response) { alert ('sometext')})
          }
  &lt;/script&gt;
  </code></pre>
  
  <p>what i have in my views.py:</p>
  
  <pre><code>def keyword_subscribe(request):
      if 'keyword_input' in request.POST:
      if 'name_input' in request.POST:
          xhr = request.GET.has_key('xhr')
          response_dict = {}
              new_keyword = request.POST['keyword_input']
          username = request.POST['name_input']
          response_dict.update({'keyword_input': new_keyword, 'name_input': username})
          power_keyword = subscribe_keyword(username,keywords)
          if power_keyword:
              response_dict.update({'success':True})
          else:
              response_dict.update({'errors':{}})
              if not username:
                          response_dict['errors'].update({'name_input': 'User ID is required'})
                  if not total and total is not False:
                          response_dict['errors'].update({'keyword_input': 'Keyword field is blank'})
          if xhr:
                  return HttpResponse(simplejson.dumps(response_dict), mimetype='application/javascript')
              return render_to_response('r2/userprofile_list.html', response_dict)
  </code></pre>