Deleting from table using AJAX
am 21.01.2008 12:14:00 von sahmHI every one
I have problem for deleting data from table using ajax
this code to insert user data and show the data in table using ajax it
work fine but for another code that use to delete data and show the
date in same table it dose not work
and this are my codes
this code for show user data
/////////////////////////////////////////////
User Table
//////////////////////////////////////////
and this is for ajax inser data
////////////////////////////////////////////
var xmlHttp;
function insertUser(emp, user, pass, email, depar)
{
if (emp.length==0)
{
document.getElementById("employee").innerHTML=""
return
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="insert_user.php"
url=url+"?employee_name="+emp+"&user="+user+"&password="+pas s
+"&e_mail="+email+"&department="+depar
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("employee").innerHTML=xmlHttp.respon seText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
//////////////////////////
and this php for insert user data
/////////////////////////////////////////
$sql = "insert into user VALUES(null, '$employee_name', '$user',
'$password', '$e_mail', '$department')";
$result = mysql_query($sql);
if($result)
{
$sql = "select * from user";
$result = mysql_query($sql);
if(@mysql_num_rows($result)!=0)
{
echo "
Employee Name | ";Employee Department | ";|
---|---|---|
\n"; echo $data['employee_name']; echo " | \n";\n"; echo $data['employee_Department']; echo " | \n";\n"; echo "\n"; echo " | \n";
}
//////////////////////////////////
and this is for ajax deleting data
var xmlHttp;
function deleteUser(emp)
{
alert("HI2");
if (emp.length==0)
{
document.getElementById("employee").innerHTML=""
return
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp1==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="delete_user.php"
url=url+"?employee_name="+emp
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("employee").innerHTML=xmlHttp.respon seText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
///////////////////////
and this for php delete user data
//////////////////////////////////
$sql = "delete from user where employee_name ='$employee_name'";
$result = mysql_query($sql);
if($result)
{
$sql = "select * from user";
//$result =
$result = mysql_query($sql);
if(@mysql_num_rows($result)!=0)
{
echo "
Employee Name | ";Employee Department | ";|
---|---|---|
\n"; echo $data['employee_name']; echo " | \n";\n"; echo $data['employee_Department']; echo " | \n";\n"; echo "\n"; echo " | \n";
}
////////////////////////
and
thank you for your help
Best
Salim
Re: Deleting from table using AJAX
am 23.01.2008 02:37:31 von nothingsoriginalontheinternetOn Jan 21, 6:14 am, sahm
> HI every one
> I have problem for deleting data from table using ajax
> this code to insert user data and show the data in table using ajax it
> work fine but for another code that use to delete data and show the
> date in same table it dose not work
I'd suggest using a JavaScript framework for dealing with AJAX, such
as Dojo (dojotoolkit.com), Mootools (mootools.net), or JQuery
(jquery.com). Dojo is nice with PHP because you can use json_encode()
in the JSON extension to pass objects between PHP and JavaScript.
These frameworks will make it easier to perform operations on HTML
tables.
Other than that, yours does not seem like a PHP problem.
-Michael Placentra II | ZCE