I want that table be refresh after deleting data
i have tried it but it’s not working. Can you pls help me how can I do it using protype.js?


this is my code

<?php 
require_once("common.php");
$row=getDetails();
//print_r($row);
 
function getDetails () {
$objLogs = new Logs();
$fields = 'id,link,filename,pageid,position,orderid';
$row = $objLogs->fnSelect('link',$fields,'1=1 ORDER BY orderid');
return $row;
}
 
 
 
if ($_GET['ref'] == 'delete') {
$condition = 'id='.$_GET['id'];
$objLogs = new Logs();
$r = $objLogs->fnDelete('link',$condition);
                header("location:index.php");
}
?>
 
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script src="js/prototype.js"></script>
<script src="js/scriptaculous.js"></script>
 
</head>
 
<body>
<div>
<table border="1" id="main">
  <tr>
    <td>Link</td>
    <td>PageID</td>
                <td>Delete</td>
  </tr>
                <div id="im">
                <?php if ($row) { foreach($row as $rs) {?>
    <tr>
    <td><?php echo $rs['link'] ?></td>
    <td><?php echo $rs['pageid'] ?></td>
                 <td><a href="#" onClick="fnDeleteLink(<?php echo $rs['id']; ?>);">Delete</a></td>
                <?php }} ?>
                </div>
  </tr>
</table>
</div>
</body>
<script>
function fnDeleteLink(id){
                if (confirm("Are you sure to delete?")){
                var pars = 'id=' + id;
                new Ajax.Updater({ success: 'im' }, 'sample.php?ref=delete', {
                method: 'get',
                parameters: pars
                });
  }
 } 
</script>
</html>

From a quick look I got on your post, your Ajax.Updater syntax is totally wrong.
You need to supply a DOM element as an argument, or in plain english,
you must say to Ajax.Updater where you want it to display the results of 'sample.php' (in other words, the place where 'sample.php' will echo)

Supposedly your table is on a <div> with id="mydiv"

try

var pars = 'id=' + id+'&success=im&ref=delete';
 new Ajax.Updater('mydiv','sample.php', {method: 'get', parameters: pars});

in sample.php, I don't know the Logs class (must be from a non official PHP library), but after you delete the record, and before you redirect to index.php, you have to add

$rows = getDetails();
if (is_array($rows)) {
echo "<table>";
foreach ($rows as $row) {
echo "<tr><td>".$row."</td></tr>;
}
echo "</table>";
} else {
echo $rows;
}

By the way, what's the point of using AJAX, if you are to redirect to index.php???

Better forget about redirecting! ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.