All pastes #459966 Raw Edit

AJAX

public text v1 · immutable
#459966 ·published 2007-04-26 19:51 UTC
rendered paste body
<?php
   require_once( 'ajason/php/Ajax.php' );
   require_once( 'functions.caching.php' );
   function fchar( $char )
   {
		$res = GetPlayerInfoC('Laughing Skull', $char);
		return "Level: $res[Level]<br />\nClass: $res[Class]";
   }

   $ajax = new Ajax();

   $ajax->registerFunction( 'fchar' );
   
   $ajaxServer = $ajax->getServer();

   if ( $ajaxServer->isRequest() )
   {
      echo $ajaxServer->handleRequest();
      exit();
   }

   $ajaxClient = $ajax->getClient();
?>
<html>
<head>
   <title>AJAX autocompletion example</title>
   <script type="text/javascript" src="ajason/javascript/json.js"></script>
   <script type="text/javascript" src="ajason/javascript/ajax.js"></script>
   <script type="text/javascript" src="overlib/overlib.js"></script>
   <script type="text/javascript">
      <?php echo $ajaxClient->getJavaScript(); ?>
		
	  loading = 0
	  
      function fetch_char( sender, arg )
      {
			if(!loading){
				x_fchar( arg, char_cb );
				loading = 1
				return overlib('<div id="ol"><img src="loader.gif" /></div>', STICKY);
			}
			
      }
      
      function char_cb( suggestion )
      {     
		document.getElementById('ol').innerHTML = suggestion
		loading = 0
      }
	  txt = ''
   </script>
</head>
<body>
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<?php
	$res = GetGuildInfoC('Laughing Skull', $_GET['guild']);
	foreach($res['Laughing Skull']['Guild'][$_GET['guild']]['Members'] as $ply){
		echo "<a onmouseover=\"fetch_char(this, '$ply[Name]');\" onmouseout=\"return nd();\" >$ply[Name]</a><br />\n";
	}
?>
</body>
</html>