Garbage characters from PHP to Javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jerm

    Garbage characters from PHP to Javascript

    Hi,

    I make a AJAX call to PHP and get back a string to my javascript
    function that looks like this:

    (0,0)-(1,1)-(25,32)

    In my javascript i break the string on the "-" character into an array
    like this:

    [(0,0)] [(1,1)] [(25,32)]

    I check the length of the string in my array at the first position and
    it says the length is 7.
    I do a length of a hardcoded string "(0,0)" and it is of length 5.

    If I do a search of my string and find the position of the "("
    character is says it is at postion 2.... this is quite messed up.
    Does any one have any idea what is happening here?

    Thanks,
    Jeremiah
  • theiviaxx@gmail.com

    #2
    Re: Garbage characters from PHP to Javascript

    On Jul 17, 8:44 am, jerm <jerm.hann...@g mail.comwrote:
    Hi,
    >
    I make a AJAX call to PHP and get back a string to my javascript
    function that looks like this:
    >
    (0,0)-(1,1)-(25,32)
    >
    In my javascript i break the string on the "-" character into an array
    like this:
    >
    [(0,0)] [(1,1)] [(25,32)]
    >
    I check the length of the string in my array at the first position and
    it says the length is 7.
    I do a length of a hardcoded string "(0,0)" and it is of length 5.
    >
    If I do a search of my string and find the position of the "("
    character is says it is at postion 2.... this is quite messed up.
    Does any one have any idea what is happening here?
    >
    Thanks,
    Jeremiah
    not sure what exactly is happening, but a better method would be to
    encode the results from php in JSON, then decode it on the javascript
    end. That way you dont have to do the splits and the integrity of the
    data is maintained.

    Comment

    • Tim Roberts

      #3
      Re: Garbage characters from PHP to Javascript

      jerm <jerm.hannley@g mail.comwrote:
      >
      >I make a AJAX call to PHP and get back a string to my javascript
      >function that looks like this:
      >
      >(0,0)-(1,1)-(25,32)
      >
      >In my javascript i break the string on the "-" character into an array
      >like this:
      >
      >[(0,0)] [(1,1)] [(25,32)]
      >
      >I check the length of the string in my array at the first position and
      >it says the length is 7.
      >I do a length of a hardcoded string "(0,0)" and it is of length 5.
      >
      >If I do a search of my string and find the position of the "("
      >character is says it is at postion 2.... this is quite messed up.
      >Does any one have any idea what is happening here?
      Well, what you describe would certainly be the case if the string contained
      exactly what you said: [(0,0)] That has a length of 7 and ( is in the 2nd
      position.

      However, my crystal ball is on the blink. Perhaps you should post your
      Javascript code, if you are willing to risk the wrath of various
      "off-topic" compaints.
      --
      Tim Roberts, timr@probo.com
      Providenza & Boekelheide, Inc.

      Comment

      Working...