繁体   English   中英

jQuery Ajax调用未在Codeigniter中调用控制器

[英]Jquery ajax call is not calling controller in codeigniter

我正在尝试使用ajax调用我的控制器函数,但它没有使用input进行调用。 这是我的ajax电话

 if(value)
            {
               $.ajax({
                   type:"POST",
                   dataType:"text",
                   cache:false,
                   contentType: "application/json; charset=utf-8",
                   url:"<?php echo base_url('Dashboard/deleteSpeciality'); ?>",
                   data:{'id':id},
                   success:function(data){
                       alert("i am in success");
                   },
                   error:function(data){
                       alert(data);
                   }
               });
            }

这是我的控制器功能。 Ajax调用正在进行,但输入却没有。 在服务器端,程序抛出错误ID未定义。

  public function deleteSpeciality($id) {
        $result= $this->Dashboard_model->getSpeciality($id);
        $path=$result[0]->ImagePath;
        $this->load->helper("file");
        delete_files($path);
        unlink($path); 
        $this->Dashboard_model->deleteSpeciality($id);
        return 1;
    }

在您的控制器$id=$_POST['id']尝试此操作,因为您正在使用Post方法,所以请勿在函数中将id作为参数传递。

public function deleteSpeciality() {
        $id=$_POST['id']
        //code here
    }

尝试这个

 public function deleteSpeciality()
    {
      $id=$this->input->post('id');
      // will print the id that was posted from ajax 
      //echo $id; 
      $result= $this->Dashboard_model->getSpeciality($id);
      $path=$result[0]->ImagePath;
      $this->load->helper("file");
      delete_files($path);
      unlink($path); 
      $this->Dashboard_model->deleteSpeciality($id);
      return 1;
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM