-
ajax返回的结果和一个字符串比较5
使用ajax,通过xmlHttp.responseText得到返回信息,用它和一个字符串比较
xmlHttp.responseText结果是success,但在
回调函数中:alert(xmlHttp.responseText == "success"); 结果为false
完全一样怎么就false?????????
问题补充:wenxiang_tune 写道===
3个等号不行吗?
三个等号不是更严格相等吗?
我也试了,也不行
问题补充:renpeng301 写道那你直接alert(xmlHttp.responseText )到底是什么啊 看看
alert(xmlHttp.responseText)就是success
但是alert(xmlHttp.responseText == "success"); 结果为false
问题补充:qq1988627 写道看看xmlHttp.responseText的返回值是多少
alert(xmlHttp.responseText)就是success
但是alert(xmlHttp.responseText == "success"); 结果为false
问题补充:a418040445 写道- var t=""+xmlHttp.responseText;
- 然后用t比。
还是不行啊
问题补充:wenxiang_tune 写道类型问题吧,都转成string应该就可以了。。。
求转换代码
问题补充:wenxiang_tune 写道你先看看xmlHttp.responseText的typeof是什么,
alert(typeof xmlHttp.responseText)
要比较的话,都是字符串直接toString()
是string 啊
问题补充:avgguy 写道你可以这样看看 xmlHttpRequest.responseText 是否多了其他符号:
- alert("\""+xmlHttpRequest.responseText+"\"");
问题补充:renpeng301 写道那你直接alert(xmlHttp.responseText )到底是什么啊 看看
这里是代码
http://www.iteye.com/problems/70078
问题补充:avgguy 写道xmlHttpRequest.responseText 是字符串类型的。
你可能输出的时候多了空格或换行符。
先 trim 一下:
var s = xmlHttpRequest.responseText.replace(/^\s*/,"").replace(/\s*$/,"");
然后再比较:
if(s=="success"){ .... }
trim后还是不行
这是代码
http://www.iteye.com/problems/70078
请胖我看看
问题补充:avgguy 写道你可以这样看看 xmlHttpRequest.responseText 是否多了其他符号:
- alert("\""+xmlHttpRequest.responseText+"\"");
好像是多了空格可是trim后还是不行
这是代码
http://www.iteye.com/problems/70078
请帮看看
问题补充:a418040445 写道
这样行不行?
- var t=""+xmlHttp.responseText;
- if($.trim(t)=="success")
- {
- alert('肯定行了。');
- }
还是不行啊
这是代码
http://www.iteye.com/problems/70078
请帮看看2011年8月16日 00:27今日起,50岁以上种牙有机会享公益免费种牙!北京京一口腔 · 顶新
10个答案按时间排序按投票排序
我知道是什么原因了,你在用ajax调用到后台的servlet时使用的是out.println(),而不是out.print(),这样你返回的前台页面的内容是“内容+换行符”,所以比较肯定是返回的false
2015年4月08日 13:25
这样行不行?
- var t=""+xmlHttp.responseText;
- if($.trim(t)=="success")
- {
- alert('肯定行了。');
- }
2011年8月16日 11:09
你可以这样看看 xmlHttpRequest.responseText 是否多了其他符号:
- alert("\""+xmlHttpRequest.responseText+"\"");
2011年8月16日 11:04
xmlHttpRequest.responseText 是字符串类型的。
你可能输出的时候多了空格或换行符。
先 trim 一下:
var s = xmlHttpRequest.responseText.replace(/^\s*/,"").replace(/\s*$/,"");
然后再比较:
if(s=="success"){ .... }
2011年8月16日 11:02
你先看看xmlHttp.responseText的typeof是什么,
alert(typeof xmlHttp.responseText)
要比较的话,都是字符串直接toString()
2011年8月16日 10:38
===
3个等号不行吗?
2011年8月16日 01:07