2017-09-11 46 views
0

ajaxを使用してコントローラ機能を呼び出そうとしていますが、入力を呼び出していません。ここに私のアヤックスコールがあります。Jquery ajax呼び出しがcodeigniterのコントローラを呼び出していません

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; 
    } 
+0

を試してみてください;' –

+0

あなたが共有してください取得中にエラーが発生しまし –

答えて

0

あなたのコントローラ$id=$_POST['id']でこれを試してみて、あなたがPostメソッドを使用しているように関数にパラメータとしてidを渡しません。

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

あなたはおそらく `$のID =の$ this - >入力 - >ポスト( 'ID')を使用する必要があり、この

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; 
    } 
関連する問題