title: Django form not valid (form.is_valide() return False) on AJAX request
body: <p>I have a form for a model which contains ImageField and i want user to be able to submit image via AJAX.</p>
  
  <p>Problem is that form.is_valide() returns False. When i dont use AJAX everything seems to be okay. I tried couple of SO answers on similar questions but with no luck.</p>
  
  <p><strong>View</strong>
  (simplified version)</p>
  
  <pre><code>def index(request):
  
      if request.method  == 'POST':
          form = UploadForm(request.POST, request.FILES)
          if form.is_valid() :
              description = form.cleaned_data['description']
              photo = form.cleaned_data['photo']
              return HttpResponse(json.dumps({'message':"some success msg"}))
          else:
  
              return HttpResponse(json.dumps({'message':'not ok'}))
      else:
          form = UploadForm()
      return render(request, 'photos/index.html', {'form':form})
  </code></pre>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;form id = "form" action="{% url 'photos:index' %}" method="post" enctype="multipart/form-data"&gt;
      {% csrf_token %}
      {{ form.as_p }}
      &lt;input type="submit" value="Submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>JS/JQuery</strong></p>
  
  <pre><code> $(document).ready(function(){
  
      function getCookie(name) {
          var cookieValue = null;
          if (document.cookie &amp;&amp; document.cookie != '') {
              var cookies = document.cookie.split(';');
              for (var i = 0; i &lt; cookies.length; i++) {
              var cookie = jQuery.trim(cookies[i]);
               // Does this cookie string begin with the name we want?
              if (cookie.substring(0, name.length + 1) == (name + '=')) {
                  cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                  break;
              }
          }
      }
          return cookieValue;
      }
  var csrftoken = getCookie('csrftoken');
  
      function csrfSafeMethod(method) {
      // these HTTP methods do not require CSRF protection
      return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
      }
  
  function sameOrigin(url) {
      // test that a given url is a same-origin URL
      // url could be relative or scheme relative or absolute
      var host = document.location.host; // host + port
      var protocol = document.location.protocol;
      var sr_origin = '//' + host;
      var origin = protocol + sr_origin;
      // Allow absolute or scheme relative URLs to same origin
      return (url == origin || url.slice(0, origin.length + 1) == origin + '/') ||
          (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') ||
          // or any other URL that isn't scheme relative or absolute i.e relative.
          !(/^(\/\/|http:|https:).*/.test(url));
      }
  
      $('#form').submit(function(e){
          e.preventDefault();
          $.ajax({
              url:'/',
              type: 'POST',
              data: new FormData($(this)),
              cache:false,
              processData: false,
              contentType: false,
              beforeSend: function(xhr, settings) {
                  if (!csrfSafeMethod(settings.type) &amp;&amp; sameOrigin(settings.url)) {
                   // Send the token to same-origin, relative URLs only.
                   // Send the token only if the method warrants CSRF protection
                   // Using the CSRFToken value acquired earlier
                      xhr.setRequestHeader("X-CSRFToken", csrftoken);
              }
              },
              success: function(data){
                  alert("yo success");
                  alert(data.message);
              }
          });
      });
  });
  </code></pre>
  
  <p>Any help i can get is much appreciated. Thanks</p>