[英]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.