hello everyone... i am trying to POST data with ajax, it is not working, since i can't/don't know how to pass the variables values with the javascript code... take a look at this, i am GETting them below, and it is working well :
<script type="text/javascript">
<!--
function getxmlobject()
{
var xmlHttp;
try
{
xmlHttp = new XmlHttpRequest();
}
catch (e)
{
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function process()
{
var xmlHttp = getxmlobject();
var fname = document.getElementById("f").value;
var lname = document.getElementById("l").value;
var url = "ins_body.php";
url = url + "?f=" + fname + "&l=" + lname;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
document.getElementById("ok").innerHTML = "Done";
}
//-->
</script>
<form>
First Name : <input type="text" id="f" /><br />
Last Name : <input type="text" id="l" /><p></p>
<input type="button" id="b" onclick="process()" value="Insert"/>
<p id="ok"></p>
</form>
and of course, ins_body.php is a normal php page that GET the variables and inserts them to the db...
<?php
$conn = mysql_connect("localhost","root","");
mysql_select_db("ajax",$conn);
$fname = $_GET["f"];
$lname = $_GET["l"];
$sql = mysql_query("insert into user (fname,lname) values ('$fname','$lname')");
?>
anyway, i don't want to GET the variables, i wanna POST them ( since a long text area value can't be done by GET, and since i prefer to POST values... ) so any idea ? what if i REQUEST data ? does it work ? here's what it is below :
function process()
{
var xmlHttp = getxmlobject();
var fname = document.getElementById("f").value;
var lname = document.getElementById("l").value;
var url = "ins_body.php";
xmlHttp.open("POST",url,true);
xmlHttp.send(null);
document.getElementById("ok").innerHTML = "Done";
}
the problem is that i can't pass the fname & lname variables to the POST engine... so ?