javascript - unexpected behaviour in if statement in php code -


the console in html file calling php code shows following results when php code executed:

php processing: debug 3: test if: in if

php processing: debug 4: false

however, i'd expect the first console result php processing: debug 3: test if: in else. e.g., seems according console wrong (if) part of if-else statement executed , don't understand why (for simple code)???

any suggestions?

php code:

//test code if($productselected_form[0] == true) {     $response_array['debug3'] = 'test if: in if'; } else {     $response_array['debug3'] = 'test if: in else'; } $response_array['debug4'] = $productselected_form[0];  //send response echo json_encode($response_array); //end test code 

javascript code (console.log in ajax call php code):

console.log("php processing: debug 3: "+msg.debug3); console.log("php processing: debug 4: "+msg.debug4); 

the problem you're comparing string value boolean evaluate true. should compare string string

//test code if($productselected_form[0] == 'true') 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -