大家好我想在5秒后自动刷新控制器功能
我在控制器功能中使用header('Refresh: 10.2');
,如
public function delete()
{
header('Refresh: 10.2');
$current_time=date('H:i:s',strtotime("+3 hours"));
$email=$this->session->userdata['email'];
$end_time=$this->model_user->get_res_endtime($email);
if($current_time>$end_time || $current_time <'00:59:59')
{
$this->model_user->move_reserve($end_time,$email);
$this->model_user->up_qty_del($email);
$this->model_user->delete_reserve($end_time,$email);
}
}
但是这个刷新整个页面还有任何只刷新功能的方法吗? 提前谢谢
答案 0 :(得分:1)
根据您的要求..您可以尝试这样的事情。 控制器:
public function delete()
{
$current_time=date('H:i:s',strtotime("+3 hours"));
$email=$this->session->userdata['email'];
$end_time=$this->model_user->get_res_endtime($email);
if($current_time>$end_time || $current_time <'00:59:59')
{
$arr["message"] = "1";
$this->model_user->move_reserve($end_time,$email);
$this->model_user->up_qty_del($email);
$this->model_user->delete_reserve($end_time,$email);
print(json_encode($arr));
exit;
}
}
jQuery:
$(document).ready(function () {
(function delete() {
//run the request
$.ajax({
type: "POST",
url: "Controller/Deletefunction",
async: true, //Hey browser! run the code
//if we prased data run:
success: function (data) {
/* we prase data (data can be anything)
* data is json_encoded data format coming from
*/
var obj = JSON.parse(data);
// if we prased data:
if (obj) {
console.log(obj);
// chrome console log should show here "success"
if (obj.count > 0) {
// Schedule the next request when the current one's complete
setTimeout(delete, 5000);
}
});
})();