Buenas
Recién empiezo yo tb con AJAX, y estuve usando la clase
xajax
Si vas a usar esa clase, podrías usar el siguiente código, adaptando la función agregar a tus necesidades de MySQL
Código PHP:
<?php
require ('xajax.inc.php');
class myXajaxResponse extends xajaxResponse
{
function addCreateOption($sSelectId, $sOptionText, $sOptionValue)
{
$this->addScript("addOption('".$sSelectId."','".$sOptionText."','".$sOptionValue."');");
}
function addCreateOptions($sSelectId, $aOptions)
{
foreach($aOptions as $sOptionText => $sOptionValue)
{
$this->addCreateOption($sSelectId, $sOptionText, $sOptionValue);
}
}
}
function agregar($tabla)
{
$objResponse = new myXajaxResponse();
if ($tabla == 1) {
$aOptions['One'] = 1;
$aOptions['Two'] = 2;
$aOptions['Three'] = 3;
} else {
$aOptions['Four'] = 4;
$aOptions['Five'] = 5;
$aOptions['Six'] = 6;
}
$objResponse->addCreateOptions("select1",$aOptions);
return $objResponse;
}
$xajax = new xajax();
$xajax->registerFunction("agregar");
$xajax->processRequests();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>xajax example</title>
<?php $xajax->printJavascript('./');
<script language="javascript" type="text/javascript">
function limpiarselect() {
oCntrl = document.getElementById('select1');
while(oCntrl.length > 0) oCntrl.options[0]=null;
}
function addOption(selectId,txt,val) {
var objOption = new Option(txt,val);
document.getElementById(selectId).options.add(objOption);
}
</script>
</head>
<body style="text-align:center;">
<div id="div1" name="div1"> </div>
<br/>
<button onclick="limpiarselect();xajax_agregar(1)" >Click Me</button>
<button onclick="limpiarselect();xajax_agregar(2)" >CLICK ME</button>
<select id="select1" name="select1">
<option value="black" selected="selected">Black</option>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>
</body>
</html>