title: Checking username availability in Django using jQuery
body: <p>I've searched a lot code on the net ... Tried  every single code in the net ... well no one seems to work for my case... what I want is while the input changes, the code will check the availability of that matricule(code). if the matricule is taken, it will display : "Matricule is taken, try another", otherwise, it display nothing.</p>
  
  <p>what should I write in my html tempalte codes, and views.py to get this done</p>
  
  <p>euhh, here's my code :
  HTML / Tempalte :</p>
  
  <pre><code>                &lt;div class="form-group"&gt;
                      &lt;!-- &lt;label class="control-label"&gt;Code&lt;/label&gt; --&gt;
                      &lt;input name="mat_personnel" id="mat_personnel" type="text" class="form-control" placeholder="Matricule" autofocus=""&gt;               
                  &lt;/div&gt;
  </code></pre>
  
  <p>Here's the view :</p>
  
  <pre><code>def checkMatricule(request):
  
       mat_personnel_form = request.GET.get('mat_personnel', '')
  
       if Personnels.objects.filter(mat_personnel=mat_personnel_form).count():
           return True
  
       return False
  </code></pre>
  
  <p>and The url.py :</p>
  
  <pre><code>    url(r'^checkMatricule/$', 'Zoe.views.checkMatricule', name='checkMatricule'),
  </code></pre>
  
  <p>and finally the Script inside the templates that gives me a headackes :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script type='text/javascript'&gt;
  
   $('#mat_personnel').keyup(function(){  
      var mat_personnel = $("#mat_personnel").val();
      if (mat_personnel == ''){
          return false
      }, "Matricule already exists");
      
      $.ajax({
          type: "GET",
          url: "/checkMatricule/",
          data: {'mat_personnel':mat_personnel},
          success: function(response){
              if (response == "True"){
                  return true
              }
              else {
                  $("#help_mat_personnel").text("Matricule already exists")
                  return false
              }
          }
  
      })
      });
  
     $('#check_Form').validate({
      rules: {
          mat_personnel: {
              required: true,
              maxlength: 5,
              remote: "/checkMatricule/"
          }
      },
      
  });
  
  &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Thank's</p>