最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to compare xmlhttp.responsetext? - Stack Overflow

programmeradmin3浏览0评论

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???

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???

Share Improve this question edited Aug 10, 2010 at 13:45 VolkerK 96.2k20 gold badges168 silver badges232 bronze badges asked Aug 10, 2010 at 13:16 nectarnectar 9,67736 gold badges82 silver badges101 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 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.

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

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

发布评论

评论列表(0)

  1. 暂无评论