minnirok
asked on
echo is printing two extra characters
Hi,
I have a simple php script:
<?php
// thePhpScript.php
echo "hello";
?>
I am calling it from a javascript function vis a vie some ajax stuff like so:
<script>
function callScriptAJAX() {
httpObj.open("GET", "thePhpScript.php", true);
httpObj.onreadystatechange = handleHttpResponse;
httpObj.send(null);
}
And then I try to print the response like so:
function handleHttpResponse() {
if (httpObj.readyState == 4) {
alert("[" + httpObj.responseText + "], length is: " + httpObj.responseText.lengt h);
}
}
</script>
But the response printed in my message box is always:
[
hello], length is: 7
Why is my php script returning a carriage return and a white space before the word 'hello'!? It's driving me crazy. I thought it would print back perfectly [hello], length is 5.
Please let me know what I'm doing wrong, thanks!
I have a simple php script:
<?php
// thePhpScript.php
echo "hello";
?>
I am calling it from a javascript function vis a vie some ajax stuff like so:
<script>
function callScriptAJAX() {
httpObj.open("GET", "thePhpScript.php", true);
httpObj.onreadystatechange
httpObj.send(null);
}
And then I try to print the response like so:
function handleHttpResponse() {
if (httpObj.readyState == 4) {
alert("[" + httpObj.responseText + "], length is: " + httpObj.responseText.lengt
}
}
</script>
But the response printed in my message box is always:
[
hello], length is: 7
Why is my php script returning a carriage return and a white space before the word 'hello'!? It's driving me crazy. I thought it would print back perfectly [hello], length is 5.
Please let me know what I'm doing wrong, thanks!
ASKER
Hmm I don't think so, it's just a parameter specifying that I want the request to be asynchronus.
Well, it really looks like something is printing a new line. I am not too familer with AJAX, I don't think its a problem on the php side.
I am not too sure its a carriage return.
Joe P
I am not too sure its a carriage return.
Joe P
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Haha gosh, yes I had one extra bit of comment junk at the top of the file - once I took it out it started working fine.
Thanks!
Thanks!
Does the 'true' in httpObj.open("GET", "thePhpScript.php", true); give it that new line character "\n" that would be the extra two characters in the string.
Joe P