2012-07-18 3 views
3

대화 상자를 여는 스크립트를 작성했으며 대화 상자 내에 데이터가있는 데이터가있는 동적 테이블이 있습니다. 직원이 불필요한 레코드를 제거 할 수 있도록 모든 레코드 옆에 삭제 단추를 배치했습니다.
Ajax 요청을 트리거하는 클릭 기능을 사용하여 데이터베이스에서 즉시 레코드를 삭제하려고했습니다.
하지만 삭제 버튼을 클릭하면 대화 상자가 닫히고 아무 것도 삭제되지 않습니다. 그것이 도움이된다면 필자의 코드를 복사했다.동적 테이블 삭제 레코드 버튼이있는 jQuery 대화 상자가 작동하지 않습니다.

모든 도움은 대단히 감사합니다 :)

//including all jquery library 

<script> 
    $(function() { 
     $("#dialog").dialog({ 
      autoOpen: false, 
        buttons: { 

       "Add to Log": function() { 
       $.ajax({ 
        type: 'POST', 
        url: "check_add.php", 
        data: $('#checkup').serialize(), 

        success: function(data) { 

          if(data == 0){//Failure 
            alert('Data was NOT saved in db!'); 
             } 
           } 
       }); 
        $(this).dialog("close"); 


       }, 
       Exit: function() { 
        $(this).dialog("close"); 
       } 
      } 

     }); 

      $("#opener").click(function() { 
      $("#dialog").dialog("open"); 
      return false; 
     }); 


     $("#reminder").dialog({ 
      width: 471, 
      autoOpen: false, 
        buttons: { 

       Exit: function() { 
        $(this).dialog("close"); 
       } 
      } 
     }); 

      $("#remind").click(function() { 
      $("#reminder").dialog("open"); 
      return false; 
     }); 


     $(".Delete").click(function() // here the delete function 
     { 
      var $this = $(this); 
      var rowid = $this.attr('name'); 
      $.ajax({ 
      type: "POST", 
      url: 'check_del.php', 
      data: { 
      'id': rowid 
       }, 
      success: function(data) { 

     if(data == 1){//Success 
      alert('Sucess'); 
      } 
     if(data == 0){//Failure 
      alert('Data was NOT saved in db!'); 
      } 
      } 
}); 
     }); 


    }); 
    </script> 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
</head> 

<body> 

<button id="opener">Add Damage</button> 
<button id="remind">Reminder</button> 

<div id="dialog" style="font-size:small;"> 
<form name="checkup" method="post" id="checkup"> 
    <table> 
    <tr><td> 
    <strong>Cases:</strong></td><td><input name="cases" type=text placeholder="Cases ID" maxlength="7" style="width:129px;"></td> 
    </tr> 
    <tr> 
    <td><strong>Comments:</strong></td> 
    <td> <textarea name="comment" placeholder="Comments Box"></textarea></td> 
    </tr> 
    </table> 
    </form> 
</div> 

<?php 

// 데이터베이스 연결 물건

$sql="select * from $tbl_name"; 
$result=mysql_query($sql); 

?> 


<div id="reminder" style="font-size:small;"> 
<form name="remind" method="post" id="remind"> 
    <table bordercolor="#000000" border="1" style="border:thin;"> 
    <th>Class</th> 
    <th>Cases</th> 
    <th>First Name</th> 
    <th>Last Name</th> 
    <th>Model</th> 
    <th>Comments</th> 
    <th> </th> 

<? 
    while($rows=mysql_fetch_array($result)){ 
$cases=strtoupper($rows['cases']); 
?> 

    <tr> 
    <td><? echo $rows['hg']; ?></td> 
    <td><? echo $cases;?></td> 
    <td><? echo $rows['firstname']; ?></td> 
    <td><? echo $rows['surname']; ?></td> 
    <td><? echo $rows['model']; ?></td> 
    <td><? echo $rows['comments']; ?></td> 
    <td><button name="<?php echo $rows['id']; ?>" class="Delete">Delete</button></td> 
    </tr> 

    </table> 
<? 
} 
?> 
    </form> 
</div> 
+0

당신이 크롬에서 아약스 트래픽을 (보고 시도 해 봤나 HTML 버튼

<input name="<? echo $rows['id'];?>" type="button" value="Delete" /> 

JQuery와 기능이 바로 아무 곳이나 클릭 jQuery 코드의 HTML의 작동 부분을 붙여 넣은 페이지, 요소 검사, '네트워크'탭 클릭) 또는 파이어 폭스 (파이어 버그 사용 ... 또한 네트워크 탭 선택)? –

+0

예 파이어 폭스에서 방화범이 끌리는 것을 사용하여 트래픽을 보았습니다. 잠깐 동안 나타나지만 멀리 화면을 캡처하거나 읽을 수 있기 전에 사라집니다. – Matthew

답변

0

내가 약간 내 코드를 변경 많은 테스트 후이

$(".Delete").live('click',function() { 
// your code go here 
}); 
+0

'''''''''''''''''''''''''''''jQuery1.7'' 이상으로''on''을 사용하고, 이전 버전에서는''live''에 대해'delegate'을 선택하십시오. – Kelly

+0

미안 해요 켈리 내가 무슨 뜻인지 이해 못 하겠니? – Matthew

+0

나는 사용하려고 시도했다. "on"대신에 "live"하지만 그것은 여전히 ​​동일한 문제에 직면 해있다. – Matthew

1

을 시도합니다. 나는 버튼을

$("input[type='button']").on('click', function() { 

    var $this = $(this); 
    var userid = $this.attr('name'); 

      $.ajax({ 
      type: "GET", 
      url: 'check_del.php', 
      data: { 
      'id': userid 

       }, 
      success: function(data) { 

     if(data == 1){//Success 
      alert('Sucess'); 
      } 
     if(data == 0){//Failure 
      alert('Data was NOT saved in db!'); 
      } 
      } 
    }); 
    }); 
관련 문제