I have a problem I can’t understand. I did many test but the result just disturb me. I have an ajax request from where I get my data like that :
$check = 0;
$output = '';
while($data = mysqli_fetch_assoc($result1)){
if($check == 0){
$output = $data['license'];
$check = 1;
}else{
$output .= ','.$data['license'];
}
}
echo $output;
the output is “2020,2021” at the end. now I have my alert in js to test the result :
success: function(data) {
alert(data); //get "2020,2021" from this alert
var tab = data.split(',');
alert(tab[0]+','+tab[1]); //get "2020,2021" from this alert
if(tab[0]=='2020'){
alert('yes1');
}else{
alert('no1');
}
if(tab[1]=='2021'){
alert('yes2');
}else{
alert('no2');
}
}
But now the problem is : the two other alerts I have are “yes1” and “no2” …. how can my 2020 equal to 2020 and 2021 not equal to 2021.
I just can’t understand, if someone can help.
Update : when I alert tab[1]+’,’+tab[0] I have :
“2021
,2020″
I don’t get when it is possible to append (my “SELECT * FROM my_table
WHERE license=’2021′ ” get all the results, so it’s not in my database)
2
Answers
As you can see if data is correct script work:
Try this (change
success =
tosuccess :
in your codeThen try this: