Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   Jquery + PHP + Smarty (https://javascript.ru/forum/dom-window/61644-jquery-php-smarty.html)

middlee 28.02.2016 07:01

Jquery + PHP + Smarty
 
Приветствую, имеется форма:
<select id="country" name="country">
        <option>Выберите страну...</option>
    {foreach $row_country as $country}
        <option value="{$country.country_id}">{$country.name}</option>
    {/foreach}
    </select>
    <select id="region" name="region" disabled>
        <option>Выберите регион...</option>
    {foreach $row_region as $region}
        <option value="{$id.region_id}">{$region.region}</option>
    {/foreach}
   </select>


Jquery функция:
$('#country').change( function() {
    var country = $('#country').val();
    $.ajax({
	type: "POST",
	url: "index.php?option=registration",
	data: country,
	success: function(data) {
            $("#region").removeAttr('disabled');
            $("#results").html(country);
            alert(country);
	}
});
});

И PHP обработчик:
class Registration extends Core {
    public function getContent() {
        global $mysqli;
        global $smarty;
        
        $res = $mysqli->query("SELECT * FROM countries ORDER BY name");
            if ($res->num_rows > 0) {
                for ($i=0; $i<$res->num_rows; $i++) {
                    $row_country[] = $mysqli->assoc($res);
                }
            $smarty->assign("row_country", $row_country);
            $smarty->assign("country", $_POST['country']);
            }
        $res_region = $mysqli->query("SELECT * FROM cities WHERE country_id=".$_POST['country']." ORDER BY region");
            if ($res_region->num_rows > 0) {
                for ($j=0; $j<$res_region->num_rows; $j++) {
                    $row_region[] = $mysqli->assoc($res_region);
                }
            $smarty->assign("row_region", $row_region);
            }
    }
}

Проблема в том, что в блоке с id="results" - значение переменной country выводит правильно, а в PHP класс ее засунуть не получается, подскажите как можно решить проблему?


Часовой пояс GMT +3, время: 15:20.