title: Using Ajax call to update a Django view
body: <p>I am new to Django, and am stuck attempting to get a variable sent from ajax to be used in the Django view. My view:</p>
  
  <pre><code>def index(request):
    if (request.is_ajax()):
      username = request.GET['user']
    else:
      username = ''
    context = {'user':username}
    return render(request, 'index.html', context)
  </code></pre>
  
  <p>and the ajax:</p>
  
  <pre><code>$.ajax({ 
    url: '/index/', 
    type: 'GET', 
    data: {user: response.name, page: page} 
  });
  </code></pre>
  
  <p>My issue is that <code>username</code> does not update in the view, based on the ajax call. I know the ajax call is working properly, because upon looking at the network response it is passing the proper updated username.</p>
  
  <p>What I believe is happening is that the view is loaded, then the ajax call occurs and updates username, but the view is not re-rendered and thus won't change. I have tried putting another render after getting the username, but that did not change anything, and I have also made a separate view for handling the ajax call, but that doesn't seem to work either, since the view always loads without ajax request being true.</p>
  
  <p>What is the way to get this working? Thanks for any help.</p>