• I’m a bit lost here, how do i run AJAX in the admin area of wordpress, my plugin basically needs to show a list of users in a tournament but i am not getting anything to change, when I select something from the dropdown nothing changes?

    My main plugin file

    function loadajax() {
    	?>
    	<script type="text/javascript">
    function showPlayers(str)
    {
    if (str=="")
      {
      document.getElementById("txtHint").innerHTML="";
      return;
      }
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","<?php bloginfo('wpurl') ?>/wp-content/plugins/bowling-plus/getregisteredplayers.php?q="+str,true);
    xmlhttp.send();
    }
    </script>
    <?php
    }
    
    add_action('admin_head', 'loadajax' );

    The file with the dropdown

    <form>
     <?php
      global $wpdb;
      $table7 = $wpdb->prefix . "bowling_plus_tournaments";
      $req7 = "SELECT * FROM $table7 order by tour_name";
      $res7 = mysql_query($req7);
    
          echo '<select name="tournaments" onchange="showPlayers(this.value)">';
    	  echo '<option>';
    	  _e('Select a tournament:', 'Bowling_Plus');
    	  echo '</option>';
          while ($data_ajax = mysql_fetch_array($res7)) {
              ?><option value="<?php echo $data_ajax['id'] ?>"><?php echo $data_ajax['tour_name'] ?></option>
              <?php
    
      }
    ?>
    </select>
    </form>
    <br />
    <div id="txtHint"><b><?php
    	_e('Players will be listed here.', 'Bowling_Plus')
    ?></b></div>

  • The topic ‘Using AJAX in wp admin for plugin?’ is closed to new replies.