Extraño error de javascript

Well it's not realy causing any errors. Anyways i'm sending ajax request and getting back just some text then i split that text in array and finaly i just wanna do some checking so let's say this is how i do it:

var response = data.split("&&", 3); // here is my response and i split it by every &&

//now i wanna do some cheking if response isn't false
if(response[0] != 'false'){
   alert('it\'s not false');

And it always says that it's not false even thou it is, i've tried to alert(response[0]) y consigo false (btw it's just a string of text)

And i didn't include my full code here because it would make to much confusion, but i know it can't be error anywhere else since when i try to alert my response[0] yo obtengo false .

preguntado el 30 de enero de 12 a las 19:01

and what does this text look like? My crystal ball is in the shop for polishing today. Maybe it's an actual javascript boolean false, and not a literal string? -

@Linas, when you alert(response[0]), are you getting false o algo así como false ? Significant whitespace cannot easily be seen in an alert box, I'd suggest checking if response[0].length es de hecho igual a 5. Chances are it isn't. -

it can't be an error anywhere else? do you alert(data)? -

¿Qué data contain? People, OP is splitting a string, so response[0] is not going to be a bool -- it's going to be a string. -

@Linas, well, there son space characters around the && operators in your string, and your split() call doesn't take them into account. If todos your strings are like this one, you might want to split on " && " en lugar de "&&". Otherwise, use Flambino's regex. -

1 Respuestas

As others have pointed out in the comments, you seem to have spaces in the value that you're comparing to false. Prueba esto:

data.split( / *&& */, 3 );

Respondido el 31 de enero de 12 a las 01:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.