阿贾克斯点击事件发生后清透与codeigniter页面 [英] Refreshing a page with codeigniter after ajax click event

查看:137
本文介绍了阿贾克斯点击事件发生后清透与codeigniter页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的PHP codeigniter函数$ C $它被称为一个jQuery AJAX函数C:

I have the following php codeigniter function code which is being called by a jquery ajax function:

            $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());

我想消息的分贝插入后刷新页面。然而,似乎没有任何事情发生。一切都正常工作,其中包括数据库插入。我究竟做错了什么?

I want to refresh the page after the db insertion of 'message'. however nothing seems to happen. everything works normally including the db insertion. What am I doing wrong?

推荐答案

您无法通过AJAX URL重定向。重定向可以使用回调函数 三种方式完成的,失败总是

You can not redirect via AJAX url. Redirect is possible using callback function in three ways done, fail and always.

例如:

$.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;
    });

这篇关于阿贾克斯点击事件发生后清透与codeigniter页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆