Connecting Tech Pros Worldwide Forums | Help | Site Map

Garbage characters from PHP to Javascript

jerm
Guest
 
Posts: n/a
#1: Jul 17 '08
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
Guest
 
Posts: n/a
#2: Jul 17 '08

re: Garbage characters from PHP to Javascript


On Jul 17, 8:44*am, jerm <jerm.hann...@gmail.comwrote:
Quote:
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.
Tim Roberts
Guest
 
Posts: n/a
#3: Jul 18 '08

re: Garbage characters from PHP to Javascript


jerm <jerm.hannley@gmail.comwrote:
Quote:
>
>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.
Closed Thread