在ajax单击事件后使用codeigniter刷新页面
我有以下php codeigniter函数代码,由jquery ajax函数调用:
$this->load->library('session'); $this->load->helper('url'); $ids = $_POST['i']; $message = $_POST['m']; var_dump($message); var_dump($ids); $sql = 'update replies set `response` = "'.$message.'" where id IN ('.implode( ',', $ids).')'; echo $sql; R::exec($sql); // works normally to here redirect($this->uri->uri_string());
我想在数据库插入’message’后刷新页面。 但似乎没有任何事情发生。 一切正常,包括数据库插入。 我究竟做错了什么?
您无法通过AJAXurl重定向。 可以通过三种方式使用回调函数进行重定向,失败和始终。
例:
$.ajax({ url: '/path/to/file', type: 'default GET (Other values: POST)', dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)', data: {param1: 'value1'}, }) .done(function(url) { // echo url in "/path/to/file" url // redirecting here if done location.href = url; }) .fail(function(url) { // echo url in "/path/to/file" url // redirecting here if failed location.href = url; }) .always(function(url) { // echo url in "/path/to/file" url // redirecting here always location.href = url; });
在你的ajax成功后,在显示成功消息后使用它
window.location="path_to redirect";
比如我正在重定向到成员控制器
window.location="member";
希望这可以帮助。