PHP and Ajax
Posted: Tue Mar 17, 2009 10:14 pm
I want to send a name using POST and then print it below using Ajax...
Please help me.I am not able to get the error.
try.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript">
function submitForm()
{
var req = null;
if(window.XMLHttpRequest)
req = new XMLHttpRequest();
else if (window.ActiveXObject)
req = new ActiveXObject(Microsoft.XMLHTTP);
req.onreadystatechange = function()
{
if(req.readyState == 4)
{
if(req.status == 200)
{
document.getElementById("result").innerHTML=req.responseText;
}
else
{
alert("An error has occured making the request");
}
}
};
req.open("GET", "reply.php", true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(null);
}
</script>
</head>
<body>
<FORM name="ajax" method="POST" action="">
<select name=mytextarea1 size=5>
<option name=Diana value=Diana> Diana </option>
<option name=Palak value=Palak> Palak </option>
<option name=Madhu value=Madhu> Madhu </option>
<option name=Priya value=Priya> Priya </option>
</select>
<input type=button value=Done onClick='submitForm()'>
</FORM>
<div id='result'></div>
</body>
</html>
reply.php
<html>
<head>
<title></title>
</head>
<body>
<?php
$name=$_POST[mytextarea1];
echo $name;
?>
</body>
</html>
Please help me.I am not able to get the error.
try.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript">
function submitForm()
{
var req = null;
if(window.XMLHttpRequest)
req = new XMLHttpRequest();
else if (window.ActiveXObject)
req = new ActiveXObject(Microsoft.XMLHTTP);
req.onreadystatechange = function()
{
if(req.readyState == 4)
{
if(req.status == 200)
{
document.getElementById("result").innerHTML=req.responseText;
}
else
{
alert("An error has occured making the request");
}
}
};
req.open("GET", "reply.php", true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(null);
}
</script>
</head>
<body>
<FORM name="ajax" method="POST" action="">
<select name=mytextarea1 size=5>
<option name=Diana value=Diana> Diana </option>
<option name=Palak value=Palak> Palak </option>
<option name=Madhu value=Madhu> Madhu </option>
<option name=Priya value=Priya> Priya </option>
</select>
<input type=button value=Done onClick='submitForm()'>
</FORM>
<div id='result'></div>
</body>
</html>
reply.php
<html>
<head>
<title></title>
</head>
<body>
<?php
$name=$_POST[mytextarea1];
echo $name;
?>
</body>
</html>