Page 1 of 1

problems with response from php page using ajax?

Posted: Wed Jan 06, 2010 1:32 am
by honkytonkman
Hi, I'm trying to use some ajax calls to call php pages from javascript.
I want to be able to return a response message from the php page to the user on the UI.

I have been succesful to a point, here is my problem:

I can succesfully display data from the php page by using the following snippet...

xmlHttpReq.onreadystatechange = function()
{
if (xmlHttpReq.readyState == 4)
{

showResponse(xmlHttpReq.responseText);

}
}

The showResponse function sets the text to a message div on the UI.

I'm having problems recieving a return value from the php page, as per the much simplified example below: I do not recieve
any text back from the php code below starting at the mysql_connect line. I dont recieve the text from the 'or die' statement, or from any subsequent test
condition statements listed below it, I've tried them all one at a time to see if any would execute, and I dont see any response text. Anything after this line does not seem to execute. If I use the first die statement as shown commented
before the mysql_connect attempt I do recieve the response text back from the die statement(HELLOWORLD). However any subsequent die statements
below the connection attempt never seem to be executed. I really dont know where to start trying to debug this, can anyone help? Thanks!!!!

<html>
<body>
<?php

$referrer = $_SERVER['HTTP_REFERER'];

//die("HELLOWORLD");

$dbhandle = mysql_connect("localhost", "mydefault", "mypassword") or die ("HELLOWORLD2");

die("HELLOWORD3");

if ($dbhandle === false)
{
die("HELLOWORD4");
}

if ($dbhandle == false)
{
die("HELLOWORD5");
}
if (mysql_connect("localhost", "mydefault", "mypassword") or die ("HELLOWORLD2"))
{
die("HELLOWORD6");
}
else
{
die("HELLOWORD7");
}

?>
</body>
</html>