1更新模板數據:index.html的細枝:從Ajax調用
<!-- 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' 的默認操作是列表中的所有用戶。當我更改過濾器時,這會在'user.js'中調用ajax函數。
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;
}
此AJAX函數調用類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