views:

36

answers:

3

The following is a part of my code :

$.post("checkbuddy.php",function(data){
  if(data!="a"){
    $("#Layer15").css({ visibility: 'visible'});
    $("#Layer10").css({ visibility: 'visible'});
    $("#Layer10").html(data);
  }
});

The condition if(data!="a") doesn't seem to be working, as checkbuddy.php returns "a". And what happens is that the HTML of Layer10 changes to "a", and thus the text shown is "a". This shouldn't be happening should it?

A: 

Extra space after the closing ?> tag or before the <?php ?

methodin
yeah,there was.It solved the problem ! Thanks!
Anant
+1  A: 

Whitespace may well be the problem. Use jQuery's .trim() function:

$.post("checkbuddy.php",function(data){
    if($.trim(data) !="a"){
        $("#Layer15").show();
        $("#Layer10").show();
        $("#Layer10").html(data);
     }
});
Peter Ajtai
A: 

Check the whitespace, as said in the other answers, but it can also be the MIME type. If checkbuddy.php is not returning a text/html or text/plain MIME type and is instead text/xml, jQuery might be converting it into an object of some sort, which would mess up the comparison.

parent5446