Noob AJAX problem

Get help using Construct 2

Post » Mon Jun 23, 2014 2:12 am

I'm new to AJAX/PHP so it might be something simple. I'm retrieving a simple string from a webpage, which is just '1|2|3|4'. Four numbers seperated by the pipe symbol. It arrives fine but when I come to parse it, tokencount tells me that it sees 4 '|' symbols when clearly there are 3.

To check it's not an error in my program, I typed in the string directly into a variable and it parse that instead. In that case, it gives the correct answer of 3, so I don't think it's anything to do with my commands.

Is this something strange about AJAX/PHP or have I done something wrong?
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Mon Jun 23, 2014 2:41 am

tokencount tells you the number of "tokens". '1|2|3|4' has four tokens. '|' isn't a "token", its the numbers that are tokens.
B
4
Posts: 13
Reputation: 376

Post » Mon Jun 23, 2014 11:37 am

Oh wow, I've been using 'tokenat' for years and always assuming the seperator was the token. Oddly, it doesn't matter if you get it wrong when using tokenat (if you assume tokenat 0 is the first seperator, you still get the first word anyway), but it does when you're using tokencount. Strangely, I was getting different results when using my AJAX.Lastdata string and an identical manual string, but it must've been because I was doing something slightly wrong.

Anyway, it's working fine now, thanks for putting that straight :)
B
25
S
5
G
3
Posts: 446
Reputation: 5,633


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, DuqueKarl, Vinterstille and 3 guests