I want my form checks my input directly using ajax and jQuery, but it cant work

this is my form input

```
<div class="form-group">
    <label for="exampleInputEmail1">NIP</label>
    <input type="text" name="nip" id="nip" class="form-control" placeholder="NIP" maxlength="18" required>
    <span id="pesannip" name="pesannip"></span>
</div>

```

jQuery from the input form above

```
<script>
  $(document).ready(function(){
    $('#nip').blur(function(){
      $('#pesannip').html('sedang mengecek');
      var nip = $(this).val();
      var len=nip.length;
      if (len==0) {
        $('#pesannip').text("NIP tidak boleh kosong");
        $('#nip').css('border', '3px #C33 solid');
      }
      else {
        if (!valid_notelp(nip)) {
          $('#pesannip').text("NIP tidak valid");
          $('#nip').css('border', '3px #C33 solid');
        }
        else if (len>0 && len<18) {
          $('#pesannip').text("NIP terlalu pendek, harus 18 angka");
          $('#nip').css('border', '3px #C33 solid');
        }else {
          $.ajax({
            type : 'POST',
            url : "<?php echo base_url('index.php/dosen/cek_nip_dosen') ?>",
            data : 'nip='+nip,
            success : function(data)
            {
              if (data=='gada') 
              {
                $("#pesannip").html("NIP bisa digunakan");
                $('#nip').css('border', '3px #090 solid');
              }
              else if(data=='ada')
              {
                $("#pesannip").html("NIP sudah digunakan oleh pengguna lain");
                $('#nip').css('border', '3px #C33 solid');
              }
            }
          });
        }
      }
    });

    function valid_notelp(notelp){
    var pola = new RegExp(/^[0-9-+]+$/);
    return pola.test(notelp);
    }
  });
</script>

```

my model named model\_dosen

```
public function cek_nip($nip)
    {
        $cek = $this->db->query("select * from detail_dosen where nip='$nip'");
        return $cek->result();
    }

```

and last my controller named dosen

```
public function cek_nip_dosen()
    {
        $this->load->model("model_dosen");
        $nip = array('nip' => $this->input->post('nip'));
        $hasil_cek = $this->model_dosen->cek_nip('$nip');
        if (count($hasil_cek)==0)
        {
            echo 'gada'; //data not exist
        }
        else 
        {
            echo 'ada';
        }
    }

```

when i insert any data (type of data number) the span always show "NIP bisa digunakan" that mean data i input not exist in the database even the data is exist in the database. 

can someone help me.

thanks in advance.