jubalbarca
Programmer
I'm trying to load variables from the server into a Javascript application with AJAX.
Here are the relevant parts of the code;
Javascript;
var name = 1;
var xmlHttp = createXmlHttpRequestObject();
var newx = 0;
function createXmlHttpRequestObject()
{
var xmlHttp;
if(window.ActiveXObject)
{
//try
//{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
//}
//catch(e)
//{
//xmlHttp = false;
//}
}
else
{
//try
//{
var xmlHttp = new XMLHttpRequest();
//}
//catch(e)
//{
//xmlHttp = false;
//}
}
if (!xmlHttp)
alert("Error makin stuff work, sesifckally creatin' the Haitch Tee Tee Pee requesterization hobject sah...");
else
return xmlHttp;
}
function processx()
{
window.alert("processx started!")
if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
{
window.alert("Server ready, sending message!")
nameserv = name;
xmlHttp.open("GET", "adbrat.php?name=" + name, true);
xmlHttp.onreadystatechange = handleServerResponsex;
xmlHttp.send(null);
}
else
setTimeout ('process()', 1000)
}
function handleServerResponsex()
{
if (xmlHttp.readyState == 4)
{
window.alert("SERVER READY! (xval)");
if (xmlHttp.status == 200)
{
window.alert("MESSAGE RECIEVED!");
xmlResponse = xmlHttp.responseXML;
window.alert(xmlResponse);
xmlDocumentElement = xmlResponse.documentElement;
window.alert(xmlDocumentElement);
newx = xmlDocumentElement.firstChild.data;
window.alert(newx);
money = newx;
window.alert(money);
//defaultx = newx;
//window.alert(defaultx);
//xmymove(newx, 20);
//window.alert(newx);
}
else
{
alert("H'im afarid I can not get into the server, m'lud. (xval) Aplolgies." + xmlHttp.statusText);
}
}
}
PHP;
<?php
$conn = mysql_connect("localhost", "", "");
$name = $_GET['name'];
mysql_select_db("test", $conn);
$sql = "SELECT user, xloc, yloc FROM user_location where user = '$name' ";
$result = mysql_query($sql, $conn) or die(mysql_error());
while ($newArray = mysql_fetch_array($result)){
$x = $newArray['xloc'];
}
header ('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
echo '<response>';
echo $x;
echo '</response>';
?>
The popup boxes after I get the message back from the PHP come up with '[object]' then stop at the one where I try and show the value of money.
Here are the relevant parts of the code;
Javascript;
var name = 1;
var xmlHttp = createXmlHttpRequestObject();
var newx = 0;
function createXmlHttpRequestObject()
{
var xmlHttp;
if(window.ActiveXObject)
{
//try
//{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
//}
//catch(e)
//{
//xmlHttp = false;
//}
}
else
{
//try
//{
var xmlHttp = new XMLHttpRequest();
//}
//catch(e)
//{
//xmlHttp = false;
//}
}
if (!xmlHttp)
alert("Error makin stuff work, sesifckally creatin' the Haitch Tee Tee Pee requesterization hobject sah...");
else
return xmlHttp;
}
function processx()
{
window.alert("processx started!")
if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
{
window.alert("Server ready, sending message!")
nameserv = name;
xmlHttp.open("GET", "adbrat.php?name=" + name, true);
xmlHttp.onreadystatechange = handleServerResponsex;
xmlHttp.send(null);
}
else
setTimeout ('process()', 1000)
}
function handleServerResponsex()
{
if (xmlHttp.readyState == 4)
{
window.alert("SERVER READY! (xval)");
if (xmlHttp.status == 200)
{
window.alert("MESSAGE RECIEVED!");
xmlResponse = xmlHttp.responseXML;
window.alert(xmlResponse);
xmlDocumentElement = xmlResponse.documentElement;
window.alert(xmlDocumentElement);
newx = xmlDocumentElement.firstChild.data;
window.alert(newx);
money = newx;
window.alert(money);
//defaultx = newx;
//window.alert(defaultx);
//xmymove(newx, 20);
//window.alert(newx);
}
else
{
alert("H'im afarid I can not get into the server, m'lud. (xval) Aplolgies." + xmlHttp.statusText);
}
}
}
PHP;
<?php
$conn = mysql_connect("localhost", "", "");
$name = $_GET['name'];
mysql_select_db("test", $conn);
$sql = "SELECT user, xloc, yloc FROM user_location where user = '$name' ";
$result = mysql_query($sql, $conn) or die(mysql_error());
while ($newArray = mysql_fetch_array($result)){
$x = $newArray['xloc'];
}
header ('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
echo '<response>';
echo $x;
echo '</response>';
?>
The popup boxes after I get the message back from the PHP come up with '[object]' then stop at the one where I try and show the value of money.