Page 1 of 1

PHP and Ajax

Posted: Tue Mar 17, 2009 10:14 pm
by dianamenezes
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>

Re: PHP and Ajax

Posted: Tue Mar 17, 2009 10:51 pm
by Benjamin
Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.  Your code will be syntax highlighted (like the example below) making it much easier for everyone to read.  You will most likely receive more answers too!

Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces.  You can even start right now by editing your existing post!

If you are new to the forums, please be sure to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]

If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online.  You'll find code samples, detailed documentation, comments and more.

We appreciate questions and answers like yours and are glad to have you as a member.  Thank you for contributing to phpDN!

Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]