• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

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!
0
minnirok
Asked:
minnirok
  • 2
  • 2
1 Solution
 
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
0
 
minnirokAuthor Commented:
Hmm I don't think so, it's just a parameter specifying that I want the request to be asynchronus.
0
 
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
0
 
ravenplCommented:
   <?php
        // thePhpScript.php
        echo "hello";
    ?>
does the <?php
is in the very first line of the script?
0
 
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!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now