Home > Backend Development > PHP Tutorial > javascript - ajax传输数据并跳转过去后发现数据为空

javascript - ajax传输数据并跳转过去后发现数据为空

WBOY
Release: 2016-06-06 20:16:36
Original
1129 people have browsed it

这是ajax的代码

<code>$(".glyphicon-pencil").click(function(){
        

        var id = $(this).attr('rel');
        var URL = "=site_url('admin/update')?>";
        $.ajax({
            type:'post',
            url:URL,
            data:{"id" : id},
            success:function(msg){
                window.location.href="=site_url('admin/update')?>";
            }
        });
        
    });</code>
Copy after login
Copy after login

这是ci框架控制的代码

<code>public function update(){
        $id = $this->input->post('id');
        echo "$id";
        exit;
        $thisdata = $this->News_model->getContent($id);

        $data['update'] = $this->News_model->getall();
        $data['id'] = $thisdata['id'];
        $data['title'] = $thisdata['title'];
        $data['content'] = $thisdata['content'];
        $data['children'] = $thisdata['children'];
        $this->load->view('admin/update',$data);
    }</code>
Copy after login
Copy after login

echo不出id值,查不出是什么原因....
是不是跳转过去数据就不在了?我另外一个删除的ajax没跳转去控制器就可以用.
如果要传数据到控制器并跳转要怎么做呢?
刚入门遇到这个问题有点迷糊了求教T_T..

回复内容:

这是ajax的代码

<code>$(".glyphicon-pencil").click(function(){
        

        var id = $(this).attr('rel');
        var URL = "=site_url('admin/update')?>";
        $.ajax({
            type:'post',
            url:URL,
            data:{"id" : id},
            success:function(msg){
                window.location.href="=site_url('admin/update')?>";
            }
        });
        
    });</code>
Copy after login
Copy after login

这是ci框架控制的代码

<code>public function update(){
        $id = $this->input->post('id');
        echo "$id";
        exit;
        $thisdata = $this->News_model->getContent($id);

        $data['update'] = $this->News_model->getall();
        $data['id'] = $thisdata['id'];
        $data['title'] = $thisdata['title'];
        $data['content'] = $thisdata['content'];
        $data['children'] = $thisdata['children'];
        $this->load->view('admin/update',$data);
    }</code>
Copy after login
Copy after login

echo不出id值,查不出是什么原因....
是不是跳转过去数据就不在了?我另外一个删除的ajax没跳转去控制器就可以用.
如果要传数据到控制器并跳转要怎么做呢?
刚入门遇到这个问题有点迷糊了求教T_T..

返回的数据你并没有使用啊,而且返回后你直接跳转到update页面了啊

你把window.location.href="=site_url('admin/update')?>";这句改成alert(msg)试试

F12 选择 network 调试~~

没用过你的模板和框架~~
"=site_url('admin/update')?>" 能解析成正确的url吗? 前端 传的 id的值 不为空 ? network都可以看到

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template