Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2009
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts

    why is ajax response text prefixing and suffixing white space?

    Hi All

    I am learning JS and ajax.. successfully writing my own working scripts.. but, being a newbie, still hit the wall alot. Today's wall really has me stumped:

    Developing locally, I am calling a page with a working XMLHttpRequest object.. and getting the response, fine. The problem is that the response is coming back with some space chars tacked on. There are like 10-12 space chars prefixed, and one space char suffixed to my response text. Even if I just stick in a single "a" char in the (now static) page that I call, it still returns:
    "<space><space><space><space><space><space><space><space><space><space><space>a<space>"
    Why?!
    Anyway, being a hacker for a living ;-), I attempt to just get around the issue (and understand what happened another day), with something like this:
    ...
    Code:
    myResponseTextHack = myObject.responseText;
    myResponseTextHack = myResponseTextHack.replace(/ /g,'~');
    ...which does change *internal* space chars to tilda chars... *BUT* the darn thing STILL has the prefixing and suffixing space chars.
    Why?!

    Can anyone guide me here?
    Thanks so much,
    -Govinda

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by cfgovinda View Post
    The problem is that the response is coming back with some space chars tacked on.
    Sounds like it is a server-side matter, not an AJAX one. Check your server-side code which supposes to return/echo the response to the AJAX object.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Apr 2009
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Kor,

    you are right. I finally did track it down to the server-side scripting language parser we are using.. it was a pre-parse script that runs invisibly like a header for every page.. it was returning line feeds that i thought were spaces.

    Thanks for replying!, I appreciate it.
    -Govinda


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •