Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AJAX xmlhttp.responseText from php echo 1

Status
Not open for further replies.

waytech2003

Programmer
Jul 14, 2003
316
US
First off let me say I am new to php and AJAX.
I am fairly good in javascript and HTML.
I am working on a new project.
I have an AJAX XMLHttpRequest sent to a php page, which returns a string via echo.
Example of my return responce would be this as the last 2 lines in my php page.

echo "TEST";
?>

I get back what looks like "TEST" in an alert box, alert(xmlhttp.responseText);
but if I test it against a string it fails. When I check it as follows...
alert(xmlhttp.responseText=="TEST");
I get false.
Is php sending something I do not know about in the echo command?
 
Hi

You probably have an empty line after the closing PHP tag and as you know, content outside the PHP tags is sent out unaltered.

That is why is recommended to not close the PHP tag at the end of the file. Remove the closing tag and your JavaScript will probably work. ( Unless you have some static content before the opening tag too. )


Feherke.
 
Thanks feherke you are correct.

I found that by trimming blank spaces off my xmlhttp.responseText, in the receiving page, all is now OK.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top