title: Django 1.9 + django-cors-headers + AJAX not working
body: <p>I'm trying to do a Cross-Site communication between my Django app that returns json and a client running AJAX.</p>
  <p>I'm using <a href="https://github.com/ottoyiu/django-cors-headers" rel="nofollow noreferrer">django-cors-headers</a> with the following configuration:</p>
  <pre><code>INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'myapp.apps.MyAppConfig',
      'corsheaders',
  ]
  
  MIDDLEWARE_CLASSES = [
      'django.middleware.security.SecurityMiddleware',
      'django.contrib.sessions.middleware.SessionMiddleware',
      'corsheaders.middleware.CorsMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
    
  ]
  
  
  CORS_ORIGIN_ALLOW_ALL = True
  </code></pre>
  <p>For now I'm trying to allow all connections just to make tests.
  This is my view:</p>
  <pre><code>def index(request):
      if request.is_ajax:     
          results={}
          results=[&quot;The password is valid&quot;]
          data_json=json.dumps(results)
          
      mimetype=&quot;application/json&quot;
      return HttpResponse(data_json,mimetype)
  </code></pre>
  <p>I tried with the decorator @csrf_exempt too.
  And finally, this is my AJAX:</p>
  <pre><code>$.ajax({
      url: &quot;http://otherdomain.com/myapp/&quot;,
      type: &quot;POST&quot;,
      crossDomain: true,
      data :{ 
              'username': $(&quot;#myName&quot;).val(),
          },
      dataType: &quot;json&quot;,
      success:function(result){
          alert(JSON.stringify(result));
      },
      error:function(xhr,status,error){
          alert(status);
      }
  });
  </code></pre>
  <p>The console is alerting this:</p>
  <blockquote>
  <p>XMLHttpRequest cannot load <a href="http://otherdomain.com/myapp/" rel="nofollow noreferrer">http://otherdomain.com/myapp/</a>. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'thisdomain.com' is therefore not allowed access.</p>
  </blockquote>
  <p>Any help will be useful. Thank you very much.</p>