ajax从javascript请求codeigniter控制器

时间:2013-11-08 15:23:55

标签: javascript php jquery ajax codeigniter

我在javascript函数中从我的codeigniter视图发出ajax请求,但没有任何反应,弹出成功警报(ok)

function show_drop_downn(){
    document.getElementById("drop_downn").style.visibility = "visible"; 
    $.ajax({
        type: "POST",
        url: "http://localhost/ok/index.php/search/ajax_delete_ntify",
        success: alert('ok'),
    }); 
}

这是我的控制器它工作正常,当我在我的浏览器中复制粘贴url(在ajax请求中使用)时,每件事情都很顺利,控制器调用模型并且它工作正常

function ajax_delete_ntify()
{
    echo "incontroller";
    $email=$this->session->userdata('email_of_user');
    $this->load->model('search_peoplee');
    $data['userid']= $this->search_peoplee->get_userid_from_email($email);
    foreach ($data['userid'] as $row)
    {
        $one=$row->userid;
    }
    $this->search_peoplee->delete_notifications($one);
    return;
}

1 个答案:

答案 0 :(得分:0)

查看:

function show_drop_downn(){
    document.getElementById("drop_downn").style.visibility = "visible"; 
    $.ajax({
        type: "POST",
        url: "http://localhost/ok/index.php/search/ajax_delete_ntify",
        success:function(
         console.log("success");
        )
    }); 
}

控制器:

function ajax_delete_ntify()
{
    echo "incontroller";
    $email=$this->session->userdata('email_of_user');
    $this->load->model('search_peoplee');
    $data= $this->search_peoplee->get_userid_from_email($email);
    $res=$this->search_peoplee->delete_notifications($data[0]->userid);
    if($res){
      echo json_encode(array('success'=>true));
    }else{
      echo json_encode(array('success'=>false));
    }
}