1

my code-

document.getElementById("lblmsg").innerHTML=xmlhttp.responseText;
                if(xmlhttp.responseText == 'Available') 
                    {
                         document.getElementById("newid").value = "";
                    }       

although response text is Available but still it is not going inside if condition???

VolkerK
  • 95,432
  • 20
  • 163
  • 226
nectar
  • 9,525
  • 36
  • 78
  • 100

2 Answers2

6

Well, that should work.

Are you sure that the response text is exactly Available? Try trimming the response like this:

if(xmlhttp.responseText.trim() == 'Available')

Do you have access to firebug? Try a console.log(xmlhttp) to find out the exact value of the responseText.

alexn
  • 57,867
  • 14
  • 111
  • 145
2

After hours of searching I found this pitfall: http://www.vertstudios.com/blog/avoiding-ajax-newline-pitfall/

This solved everything without $.trim(). Somewhere in my included files was a lonely linebreak!

akjoshi
  • 15,374
  • 13
  • 103
  • 121
Sven
  • 21
  • 1