ajax方式调用,成功返回了一个"success"字符串。如图所示但是在ajax的success代码里面判断data是否等于"success",居然是不相等的。始终不会有弹框出来。
为神马?附代码。。$.ajax({
'url': 'ajaxuserfollow.php',
'data': {'method': 'followUser', 'fans': fans,'superStar':superStar},
'success': function(data){
if(data == "success"){
alert("success");
$(this).attr("class")="guanzhu-Y";
}else if(data == "error"){
alert("error");
}
}
});
为神马?附代码。。$.ajax({
'url': 'ajaxuserfollow.php',
'data': {'method': 'followUser', 'fans': fans,'superStar':superStar},
'success': function(data){
if(data == "success"){
alert("success");
$(this).attr("class")="guanzhu-Y";
}else if(data == "error"){
alert("error");
}
}
});
你下面一句代码是错误的
var _this=this;
$.ajax({
'url': 'ajaxuserfollow.php',
'data': {'method': 'followUser', 'fans': fans,'superStar':superStar},
'success': function(data){
if(data == "success"){
alert("success");
$(_this).attr("class")="guanzhu-Y";
}else if(data == "error"){
alert("error");
}
}
});
或直接试试 data.trim=="success" 试试
没有执行 alert wzs_xyz老湿
谢谢!!!!!!!!!!用data.trim() 就可以了 。。但是为啥呢 我在被调用的ajax里面 直接是echo "success"的 并没有什么空格呀
然后在JS页面中
alert(data.length);//结果肯定>7
之后
alert($.trim(data).length);//过滤空格之后,结果应该=7