javascript - indexOf() function always return zero even have the same string -


i have variable in javascript

var hidden = "class_code,other"; 

then have ajax returning value

$.ajax({ type: "post", data: $("#myform").serialize, success: function(data){     if(hidden.indexof(data)){     //mycode here  } } }); 

but doesn't work, try use alert() print hidden.indexof(data) , returns 0, try alert data , it's returning "class_code".

why script doesn't work hidden var contains data?

indexof returns position matching string begins. since class_code @ beginning of class_code,other, 0. when string isn't found, returns -1. correct way test if string found with:

if (hidden.indexof(data) != -1) 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -