ajax返回的结果和一个字符串比较

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 写道
Js代码   收藏代码
  1. var t=""+xmlHttp.responseText;  
  2. 然后用t比。  

还是不行啊

问题补充:
wenxiang_tune 写道
类型问题吧,都转成string应该就可以了。。。

求转换代码

问题补充:
wenxiang_tune 写道
你先看看xmlHttp.responseText的typeof是什么, 
alert(typeof xmlHttp.responseText) 
要比较的话,都是字符串直接toString()

是string 啊

问题补充:
avgguy 写道
你可以这样看看 xmlHttpRequest.responseText 是否多了其他符号: 

Javascript代码   收藏代码
  1. 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 是否多了其他符号: 

Javascript代码   收藏代码
  1. alert("\""+xmlHttpRequest.responseText+"\"");  

好像是多了空格可是trim后还是不行 

这是代码 
http://www.iteye.com/problems/70078 
请帮看看

问题补充:
a418040445 写道
 

这样行不行? 
Js代码   收藏代码
  1. var t=""+xmlHttp.responseText;     
  2. if($.trim(t)=="success")  
  3. {  
  4.     alert('肯定行了。');  
  5. }  

还是不行啊 
这是代码 
http://www.iteye.com/problems/70078 
请帮看看
2011年8月16日 00:27
今日起,50岁以上种牙有机会享公益免费种牙!北京京一口腔 · 顶新

10个答案按时间排序按投票排序

0 0

我知道是什么原因了,你在用ajax调用到后台的servlet时使用的是out.println(),而不是out.print(),这样你返回的前台页面的内容是“内容+换行符”,所以比较肯定是返回的false

2015年4月08日 13:25
0 0

 

这样行不行? 

Js代码   收藏代码
  1. var t=""+xmlHttp.responseText;     
  2. if($.trim(t)=="success")  
  3. {  
  4.     alert('肯定行了。');  
  5. }  

2011年8月16日 11:09
0 0

你可以这样看看 xmlHttpRequest.responseText 是否多了其他符号: 

Javascript代码   收藏代码
  1. alert("\""+xmlHttpRequest.responseText+"\"");  

2011年8月16日 11:04
0 0

xmlHttpRequest.responseText 是字符串类型的。 
你可能输出的时候多了空格或换行符。 
先 trim 一下: 
var s = xmlHttpRequest.responseText.replace(/^\s*/,"").replace(/\s*$/,""); 
然后再比较: 
if(s=="success"){ .... }

2011年8月16日 11:02
0 0

你先看看xmlHttp.responseText的typeof是什么, 
alert(typeof xmlHttp.responseText) 
要比较的话,都是字符串直接toString()

2011年8月16日 10:38
0 0

类型问题吧,都转成string应该就可以了。。。

2011年8月16日 09:57
0 0

Js代码   收藏代码
  1. var t=""+xmlHttp.responseText;  
  2. 然后用t比。  

2011年8月16日 09:38
0 0

看看xmlHttp.responseText的返回值是多少

2011年8月16日 09:38
0 0

那你直接alert(xmlHttp.responseText  )到底是什么啊 看看

2011年8月16日 07:57
0 0

=== 
3个等号不行吗?

2011年8月16日 01:07



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值