Possible Duplicate:
Passing multiple parameter to PHP from Javascript
I am currently trying to pass data from Javascript to PHP. I have the PHP script is accessed from the Javascript except no information is stored in the $_Post
variable. I even tried the $_Get
and the $_Request
to make sure it was not stored there. It was not. Can someone please help me? The function that I am using is below. The variable str is a string of things that I create elsewhere in the javascript that I feel as though are not useful to see. They are not gotten from an HTML form. The PHP script is also below.
Thanks
Javascript function that is supposed to do the passing of information.
function postForm(str) {
var xmlHttp;
try
{ // Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{ // Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
} catch (e)
{
alert("ERROR: CAN NOT POST DATA");
}
}
}
try
{
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
alert(xmlHttp.responseText);
}
}
xmlHttp.open("POST","BigInt2.php",true);
postStr = "msg="+escape(str);
alert("SENDING: "+postStr);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send(postStr);
} catch(e)
{
alert("ERROR POSTING DATA");
}
}
PHP function that is supposed to do the printing of infomration as a proof of concept that the information is stored in the $_Post global variable. BigInt2.php
<?php
echo$_Post['msg'];
echo$_Get['msg'];
echo$_Request['msg'];
?>
You're mistyping (post and get) try this in your php file and see if it works
echo $_POST['msg'];