1: index.htmlTwig: шаблон обновления данных от АЯКС вызова
<!-- begin filter -->
<input type="radio" id="" name="top10" value="top10">Top 10
<input type="radio" id="" name="top20" value="top20">Top 20
<input type="radio" id="" checked="checked" name="all" value="all">All
<!-- end filters -->
{% for user in users %}
{% include 'userslist.html' %}
{% endfor %}
В 'index.html' действие по умолчанию является список всех пользователей. Когда я меняю фильтр, это вызывает функцию ajax в 'user.js'.
2: user.js
$.ajax({
url: 'user/find/'+params,
type: 'get',
data: null,
async: false,
dataType: 'html',
success: function(dataJson){
?????
},
error: function(jqXHR, textStatus, errorThrown){},
complete: function(jqXHR, textStatus){}
});
return jsonContratos;
}
Эта функция Аякса вызвать класс User.php
3: User.php
class User extends AppRequest
{
public function __construct(){}
public function index_action()
{
$this->template('index.html', Array('users' => $this->find()));
}
public function find()
{
$arrayUsers = dataBase->findUsersByFilters($_GET['params']);
if($this->isAjaxRequest()){
$array = Array('users' => $arrayUsers)
$this->template('index.html', $array);
}else{
return $arrayUsers;
}
}
}
Вопросы: -Как я могу отправить новых пользователей lis t в шаблон, используя обратный вызов ajax? -Как лучший способ сделать это? -Вы можете сделать это с Json?
Добро пожаловать в Stackoverflow! Первое замечание: 'async: false' -> no. – moonwave99