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.length);
        }
    }    
    </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!
LVL 7
minnirokAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BogoJokerCommented:
Hi minnirok,

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
minnirokAuthor Commented:
Hmm I don't think so, it's just a parameter specifying that I want the request to be asynchronus.
BogoJokerCommented:
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
ravenplCommented:
   <?php
        // thePhpScript.php
        echo "hello";
    ?>
does the <?php
is in the very first line of the script?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
minnirokAuthor Commented:
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!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.