One of my team mate is encountering a problem. Actually he have a database with columns id and name. He have inserted the value manually and then retrieving the values using AJAX function. Below I am attaching the function using which he is retrieving data
from the database.
<script type="text/javascript">
window.onload = showALL;
function showALL()
{
var xmlrqst;
if(window.XMLHttpRequest){
xmlrqst = new XMLHttpRequest();
}
else{
xmlrqst = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlrqst.onreadystatechange = function(){
if(xmlrqst.readyState==4 && xmlrqst.status==200)
{
document.getElementById("userall").innerHTML = xmlrqst.responseText;
}
}
xmlrqst.open("GET","post.php?get=1",true);
xmlrqst.send();
}// showAll()
</script>
the aforementioned javascript is in the index.php.
here you can see that i am using a post.php and is passing parameter through the url to post.php
below is the code that is being executed in the post.php
<?php
if(isset($_GET['get']))
{
if($_GET['get']!=1)
{
echo "error";
}
$showAll = "SELECT * FROM names";
$showAllQuery = mysql_query($showAll,$con);
if(!$showAllQuery){ die("error".mysql_error());}
echo "<table>";
echo "<th>ID</th>";
echo "<th>NAME</th>";
while($output=mysql_fetch_array($showAllQuery))
{
$out = $output['id'];
echo"<tr>";
echo "<td>{$output['id']}</td>";
echo "<td>{$output['name']}</td>";
echo "<td><a href=\"#\">delete</a></td>";
echo "</tr>";
}
echo "</table>";
}
?>
in the post.php he is generating the table with user data and it is being displayed in the index.php file in the <div ></div> section.
Now, lets discuss his problem. The problem is the data are generated in the post.php and is displayed in the index.php in a certain div. How can he delete value from database using AJAX?
Bangalorean Bangalore's City Information Directory!
mohith.net
Member
115 Points
72 Posts
Some help needed
May 29, 2012 09:47 AM|LINK
One of my team mate is encountering a problem. Actually he have a database with columns id and name. He have inserted the value manually and then retrieving the values using AJAX function. Below I am attaching the function using which he is retrieving data from the database.
<script type="text/javascript"> window.onload = showALL; function showALL() { var xmlrqst; if(window.XMLHttpRequest){ xmlrqst = new XMLHttpRequest(); } else{ xmlrqst = new ActiveXObject("Microsoft.XMLHTTP"); } xmlrqst.onreadystatechange = function(){ if(xmlrqst.readyState==4 && xmlrqst.status==200) { document.getElementById("userall").innerHTML = xmlrqst.responseText; } } xmlrqst.open("GET","post.php?get=1",true); xmlrqst.send(); }// showAll() </script> the aforementioned javascript is in the index.php. here you can see that i am using a post.php and is passing parameter through the url to post.php below is the code that is being executed in the post.php <?php if(isset($_GET['get'])) { if($_GET['get']!=1) { echo "error"; } $showAll = "SELECT * FROM names"; $showAllQuery = mysql_query($showAll,$con); if(!$showAllQuery){ die("error".mysql_error());} echo "<table>"; echo "<th>ID</th>"; echo "<th>NAME</th>"; while($output=mysql_fetch_array($showAllQuery)) { $out = $output['id']; echo"<tr>"; echo "<td>{$output['id']}</td>"; echo "<td>{$output['name']}</td>"; echo "<td><a href=\"#\">delete</a></td>"; echo "</tr>"; } echo "</table>"; } ?>in the post.php he is generating the table with user data and it is being displayed in the index.php file in the <div ></div> section.
Now, lets discuss his problem. The problem is the data are generated in the post.php and is displayed in the index.php in a certain div. How can he delete value from database using AJAX?
Bangalore's City Information Directory!
Mudasir.Khan
All-Star
15346 Points
3142 Posts
Re: Some help needed
May 29, 2012 09:55 AM|LINK
instead usethen in javascript{callAjax("delete.php?id="+id,result);{