Smarty+PHP+хAjax

Platon_82

Новичок
Smarty+PHP+хAjax

Подскажите как скрипт сделаный в связке PHP+хAjax сделатьв связке Smarty+PHP+хAjax

PHP:
<?php

require ('xajax/xajax.inc.php');

$xajax = new xajax(); 
$xajax->registerFunction("getList1");
$xajax->registerFunction("getList2");
$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>Адреса AJAX</title>
	<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
	<?php $xajax->printJavascript('xajax/'); ?>
	<script language='javascript'>
	function init()
	{
		xajax_getList1();
	}
	</script>
</head>
<body onload="init()">
<form name='mainform'>
Регион:
<div id="div1">(не загружено)</div>
Населенный пункт:
<div id="div2">(не загружено)</div>
</form>
</body>
</html>
<?php

function getList1()
{
	$text = '';
	$lines = file('002region.txt');
	for ($i=0; $i<count($lines); $i++)
	{
		$line = trim($lines[$i]);
		if ($line == '') continue;
		list($regionID, $regionName) = explode('|', $line, 2);
		$text .= "<option value='$regionID'>$regionName</option>";
	}
	$text = "<select name='region' onchange='xajax_getList2(this.options[this.selectedIndex].value)'>$text</select>";

	$objResponse = new xajaxResponse();
	$objResponse->addAssign("div1", "innerHTML", $text);
	return $objResponse;
}

function getList2($region)
{
	$text = '';
	$lines = file('002city.txt');
	for ($i=0; $i<count($lines); $i++)
	{
		$line = trim($lines[$i]);
		if ($line == '') continue;
		list($cityID, $regionID, $cityName) = explode('|', $line, 3);
		if ($regionID == $region)
		{
			$text .= "<option value='$cityID'>$cityName</option>";
		}
	}
	$text = "<select name='city'>$text</select>";

	$objResponse = new xajaxResponse();
	$objResponse->addAssign("div2", "innerHTML", $text);
	return $objResponse;
}

?>
 
Сверху