title: How to check if username exists without refreshing page using wordpress
body: <p>I want to check a text field in form that if username exists in database or not.i want it without refreshing page and i am using Wordpress.I know it is possible through ajax but i have tried ajax in Wordpress and any ajax code didn't run on it. Kindly provide any piece of code or any helpful link. Last time i have tried this but didn't work:</p>
  
  <pre><code>&lt;?php
  if(!empty($user_name)){ 
  
  $usernamecheck = $wpdb-&gt;get_results("select id from wp_teacher_info where      user_name='$user_name'");
  if(!empty($usernamecheck)){
  echo'username not available';
  }
  else {
  
  }
  }?&gt;
  
  &lt;label for="user_name" id="user_name"&gt;Username: &lt;/label&gt;
  &lt;input type="text" name="user_name" id="user_name" required/&gt;
  &lt;span id="user-result" &gt;&lt;/span&gt;
  
  
  &lt;script type="text/javascript"&gt;
  
  jQuery("#user_name").keyup(function (e) { //user types username on   inputfiled
  
  var user_name = jQuery(this).val(); //get the string typed by user
  jQuery.post('teacher_form.php', {'user_name':user_name}, function(data) { 
  jQuery("#user-result").html(data); //dump the data received from PHP page
  });
  });
  &lt;/script&gt;
  </code></pre>