2014-02-11 2 views
0

나는 하나의 양식을 가지고 있으며 제거 단추가있는 여러 양식 필드가 있습니다. 모든 데이터는 DB.now에서 오는 것입니다. 제거 단추를 클릭하면 DB에서이 데이터를 제거하고 싶습니다. 아약스.PHP에서 데이터 삭제 PHP와 AJAX를 사용하여

PHP 코드 : -

<?php 
    for($i=0;$i<$hdntotal;$i++) 
    { 
?> 
      <div class="expform" id="<?=$i;?>"> 
      <label class="explabel">Expert Name: </label><input type="text" id="txtexpname" name="txtexpname[]" class="expfield" placeholder="Enter name of expert" value="<?=$expert_name[$i]; ?>"/> 
      <div class="clearboth"></div> 
      <label class="explabel">Link of the expert work: </label><input type="text" id="txtexplink" name="txtexplink[]" class="expfield" placeholder="Enter link of expert work" value="<?=$expert_user_links[$i];?>"/> 
      <div class="clearboth"></div> 
      <label class="explabel">Title of the review: </label><input type="text" id="txtreviewtitle" name="txtreviewtitle[]" class="expfield" placeholder="Enter title of review" value="<?=$expert_title[$i];?>"/> 
      <div class="clearboth"></div> 
      <label class="explabel">Details of the review: </label> 
       <textarea id="txtrevdetails" name="txtrevdetails[]" class="expfield" placeholder="Enter details of review"><?=$expert_details[$i]; ?></textarea> 
       <div class="clearboth"></div> 
       <input type="hidden" value="<?=$rev_id[$i];?>" name="oldexprevids[]" > 
       <input type="button" class="delReview" id="<?=$rev_id[$i];?>" value="Remove"> 
       <div class="line"></div> 
      </div> 
<?php 
    } 
?> 

JS 코드 : -

/*AJAX Function for Delete Expert Review*/ 
jQuery(document).ready(function($) { 

    $('button.delReview').each(function(){ 

     var $this = $(this); 

     $this.click(function(){ 

      var deleteItem = $this.attr('id'); 

      $.ajax({url:'delete-expreview.php?action='+deleteItem}).done(function(data){ 

       //colect data from response or custom code when success 

      }); 
     return false; 
     }); 

    }); 
}); 
/*End fo AJAX Function*/ 

삭제 페이지 코드 : -

$id = $_REQUEST['action']; 
$sql5 = "delete from cc_tbl_car_review where id = '$id'"; 
$result5 = mysqli_query($db,$sql5) or die('Fetch Error'); 

하지만 난 점점 아니에요 어떤 결과가 있다면 어떤 결과가 나옵니다. 나와 공유하십시오.

+1

삭제 페이지에서 $ _REQUEST [ 'action'] 값을 얻고 있습니까? (inspect 요소/네트워크 콘솔을 통해 확인 했습니까?) ?? –

답변

2

ajax 함수에 고유 ID 전달. Onclick 함수는 삭제를 위해 고유 ID를 가져야합니다. 와 Ajax 코드 은 $ _POST [ 'ID']처럼 고유 ID를 얻고 작업을 수행이

$('.delReview').click(function(){ 
     var id =$(this).attr('id'); 
     $.ajax({ 
     type: "POST", 
//path to delete php page 
     url:"pathto/delete.php", 
     data: "id="+id, 
     success:function(result){ 

      //here is your success action 
      //for refreshing page use this 
      $("#result1").html(result); 
     }); 
}); 

같이하고 delete.php에있을 것입니다.

0

문제는 아약스 전화와 관련이 있습니다. 우리는 이름에 데이터를 전달해야 : 같이됩니다

하여 Ajax 호출과 같은 값 paai을이

$.ajax({ 
    url:'delete-expreview.php', 
    data:{action:deleteItem}, 
    success:function(result){alert("message");} 

});

관련 문제