2014-04-11 2 views
-2

Yii에서 프로젝트를 구현했습니다. 아약스 함수를 사용하여 테이블에서 데이터를 삭제하고 싶습니다. 그것은 작동하지 않습니다ajax를 사용하여 세 개의 다른 테이블에서 데이터 삭제

<td id="data"> 
    <?php 
     echo $i++; 
    ?> 
</td> 
<td id="data"> 
    <?php 
     $type=Ingredienttype::model()->find("id=$type_id"); 
     echo $type['ingredient_type']; 
    ?> 
</td> 
<td id="data"> 
    <?php 
     $type1=Ingredient::model()->find("ingredient_id=$ingredient_id"); 
     //echo $ingredient_id; 
     echo $type1['ingredientname']; 
    ?> 
</td> 
<td id="data"> 
    <?php 
     echo $quantity; 
    ?> 
</td> 
<td id="data"> 
    <?php 
     $mes_type=Measuringtype::model()->find("id=$measuringtype"); 
     echo $mes_type['measuringname']; 
    ?> 
</td> 

<input type="button" id="<?php echo $type_id; ?>" name="doesntMatter" class="REMOVETHIS btn btn-inverse btn-xs" 
       value="Del" onclick="removeRow1(this.id,<?php echo $model->recipe_id ?>)"/></td> 

: 나는 하나의 행으로이 세 테이블의 데이터를 표시

<script> 
function removeRow1(x,y){  
    alert("Are sure want to delete"); 

    $.ajax({ 
     url: '<?php echo Yii::app()->createAbsoluteUrl("ingredients/delete1"); ?>', 
     type: 'POST', 
     data: 'x1='+x+'&r_id='+y, 
     success: function(res) 
     { 
      //alert(res); 
      ////$("#truth").html(res); 
     }, 
     error:function(){ 
      alert("Failed request data from ajax page"); 
     } 
    });  
} 
</script> 

: 내보기 부분에서

public function actionDelete1(){ 
    if (isset($_POST['x1']) && isset($_POST['r_id'])) { 
     $hid=$_POST['x1']; 
     $rid=$_POST['r_id']; 

     echo $_POST['x1'].'recipe_id'.$_POST['r_id']; 

     $query="delete from ingredients where ingredienttype_id='$hid'"; 
     $query1=Yii::app()->db->CreateCommand($query)->execute(); 

     $this->redirect(array('recipe/update','id'=>$rid)); 
    } 

} 

: 내 컨트롤러에서

내가 쓴 . 아약스를 사용하여 ID를 삭제하는 방법을 제안 해주세요.

+5

그리고 ... 당신의 질문은 ...? –

+0

그것의 작동하지 않는 친구 –

+1

글쎄, "젠체하는"분명히 모든 것이 잘 작동했다면 여기에 없을 것이다. 문제에 대해 더 자세히 이야기 해 주시겠습니까? 조용히 실패하고 있습니까? 시공간 연속성을 깨고 있습니까? 오류 메시지가 있습니까? 오류가 클라이언트 측 또는 서버 측입니까? 어느 시점에서 오류가 발생합니까? (데이터를 보낼 때 서버에서 처리 할 때 응답을 처리 할 때 ...?)? 알다시피, 우리가 추측 할 수없는이 모든 것들이 ... –

답변

1

먼저 당신이 $hid이 아직 정의되지 않은

$query="delete from ingredients where ingredienttype_id='$hid'"; 

있다!

$hid 또는 $rid 중 하나를 사용 하시겠습니까?

둘째, 아약스와 함께 매개 변수를 보내면 데이터가 개체 여야하며 문자열로 작동하는지 여부는 알 수 없습니다. 그래서 확실하게, 다음과 같이 객체를 사용해보십시오.

$.ajax({ 
    url: '<?php echo Yii::app()->createAbsoluteUrl("ingredients/delete1"); ?>', 
    type: 'POST', 
    data: {'x1':x,'r_id':y}, 
    success: function(res) 
    { 
    //---- 
+0

하지만 그 작동하지 않습니다. –

관련 문제