使用php点击锚标签后如何显示特定记录?

时间:2017-01-10 07:00:38

标签: javascript php jquery html ajax

我有两个链接,删除和查看。删除工作完美。我在查看链接上遇到了问题。单击视图链接后,我必须显示特定记录。如果您注意到我写了href='delete.php?function=delete&del_id=$id'删除锚标记。它调用delete.php文件并删除特定记录。我想知道如何写视图锚标签来显示记录?请检查下面的图像。我想点击视图并在文本字段中显示记录。添加了PHP文件。请检查我的ajax代码。它也不起作用。 Ajax代码在这里不起作用。我必须在文本字段中显示输出。如果我直接写$ id = 2,那么它是在alert中显示记录。希望你们现在能理解。你能帮助我吗?

enter image description here

//delete.php
function view($conn) {
    $id=$_GET['view_id'];
    $admin_view="SELECT * from view_table WHERE Id=$id";
    $result = $conn->query($admin_view);
    if (isset($result->num_rows) > 0) {
         // output data of each row
        while($row = $result->fetch_assoc()) {
            $parent_name=$row['Name'];
            $parent_email=$row['Email'];
            $admin_mobile=$row['Mobile_no'];  
        }
    }
}
 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
     <a href='delete.php?function=delete&del_id=$id' >Delete</a> 
     <a href='#Popup' onClick='a_onClick(<?php $id?>)' class='btn-view'>View</a>

             <form action="#" method="post">
                 <input type="text" name="Name" placeholder="username"  value="<?php echo $parent_name;?>" >
                 <input type="email" name="email" placeholder="email"  value="<?php echo $parent_email;?>" >
                 <input type="text" name="Mobile_no" placeholder="Mobile no"  value="<?php echo $admin_mobile;?>" >

                 <a href="#" class="cancel">Cancel</a> <span class="close"></div>
             </form>

     <script>
         function a_onClick(id) {
var id = id;
var Name=$('#name').val();
             $.ajax({    //create an ajax request to load_page.php
                 type: "GET",
                 url: "delete.php?function=view&view_id=id",  
                 data:'Name='+Name,          
                 dataType: "html", //expect html to be returned                
                 success: function(response) {                    
                     // $("#responsecontainer").html(response); 
                     alert(response);
                 } 
             });
         }
     </script>

1 个答案:

答案 0 :(得分:0)

您需要更改一些更改

 <a href='#Popup' onClick='a_onClick(<?= $id ?>)' class='btn-view'>View</a>

<script>
         function a_onClick(id) {
              var id = id;

             $.ajax({    //create an ajax request to load_page.php
                 type: "GET",
                 url: "delete.php?function=view&view_id=id",  
                 data:'Name='+Name,          
                 dataType: "html", //expect html to be returned                
                 success: function(response) {                    
                     // $("#responsecontainer").html(response); 
                     alert(response);
                 } 
             });
         }
     </script>

希望对你有所帮助

相关问题