dsjojts9734 2017-02-25 07:21
浏览 35

Codeigniter如何在响应后将值传递给ajax?

I'am new in codeigniter now get stuck in passing value to ajax after respone. I tried to echo value after php check but when ajax response it show all entire html element, I just want value that echo from php only, any ideas pls. Here is my code in controller

public function index(){
    //Fetch page template
    if(isset($_POST['email'])){
        $this->data['email'] = $this->sign_up_m->get_by(array('email' => $_POST['email']), TRUE );
        if(empty($this->data['email'])){
            $this->sign_up_m->save(array('email' => $_POST['email'], 'date' => date('Y-m-d H:i:s')));
        }else{
            $this->data['email'] = $_POST['email'];
            echo'exist';
        }
    }
    $page = $this->uri->segment(1);
    if( is_null($page)){
        $page = 'home';
    }
    $this->data['home'] = $this->page_m->get_by(array('nice_name' => $page),TRUE);
    count($this->data['home']) || show_404(current_url());
    //Fetch page data
    $method = '_'. $this->data['home']->template;
    if(method_exists($this, $method))
    {
        $this->$method();
    }
    else
    {
        log_message('errors','Could not load template'. $method. 'in file'. __FILE__. 'at line'. __LINE__);
        show_error('Could not load template', $method);
    }
    $this->data['subview'] = $this->data['home']->template;
    $this->load->view('_layout_main', $this->data);
}

Here is my ajax

$('.sign_up').click(function(){
        var email = $('.email_signup').val();
        var validate = isValidEmailAddress(email);
        if(!isValidEmailAddress(email)){
            $('.invalide_email').css('display','inline');
            return;
        }
        $.ajax({
            type: 'post',
            url: 'http://localhost:8080/project/www.example.com/',
            data: {
                email: email,
            },
            beforeSend: function(){
                $('#load').css('display','inline');
            },
            success: function( response ) {
                $('#load').css('display','none');
                console.log(response);
            }
        });

    });
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?