Forum Moderators: open

Message Too Old, No Replies

xmlHttp.open

xmlHttp.open

         

cody7

4:11 pm on Feb 20, 2008 (gmt 0)

10+ Year Member



Hi guys i can't get this to work

this is the onclick function

function process()
{
// only continue if xmlHttp isn't void
if (xmlHttp)
{
// try to connect to the server
try
{

var firstNumber = document.getElementById("firstNumber").value;
var secondNumber = document.getElementById("secondNumber").value;

// ($_POST)
var params = "firstNumber=" + firstNumber + "&secondNumber=" + secondNumber;
xmlHttp.open("POST", "compute.php", true);
xmlHttp.onreadystatechange = handleRequestStateChange;
xmlHttp.send(params);
}
// display the error in case of failure
catch (e)
{
alert("Can't connect to server:\n" + e.toString());
}
}
}

and this will be the compute.php

header('Content-Type: text/xml');
$firstNumber = $_POST['firstNumber'];
$secondNumber = $_POST['secondNumber'];
.....

my problem

I tried the GET approach and I make it to work so now Im trying the POST approach but

$firstNumber and $secondNumber is not getting any value. can't figure out what went wrong. please help

eelixduppy

4:32 pm on Feb 20, 2008 (gmt 0)



Are you getting an script errors? Also, try adding the following to set the request header:

XMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

cody7

5:18 pm on Feb 20, 2008 (gmt 0)

10+ Year Member



no script error. but when i try to print the value of the 2 variables - no values.

Br3nn4n

1:58 am on Feb 24, 2008 (gmt 0)

10+ Year Member



Sorry I can't help with a suggestion, but I was having this EXACT same problem. I couldn't get it to actually post the data....if someone can explain how to get ajax to work with POST I'll love them..lol

mehh

12:14 pm on Feb 24, 2008 (gmt 0)

10+ Year Member



Can we see the
handleRequestStateChange
handler please? Does xmlHttp have a value? Also does your PHP script actualy output anything?