Jquery 比较字符串在 POST 中不起作用
我有一个 jquery 邮政代码,可以根据响应有两种不同的反应。如果响应是 a
那么我想 alert()
如果它不是 a
那么我想更新一个 div (ratebox) 。但是,其中一行(如下)不起作用。当它应该发出警报时,它会将字母 a
附加到费率框上。我检查了answerating.php 确实生成了字母a。
查询:
$.post('../answerrating.php' , {answer_id: answer_id , direction: 2} , function(response){
if (response == 'a'){ //this line doenst work
alert("error");
}
else {
ratebox.text(response);
}
});
I have a jquery post code that can have two different reactions based on the response. if the response is a
then i would like to alert()
if it is not a
then i would like to update a div (ratebox). However, one of the lines (below) isn't working. It appends the letter a
onto the ratebox when it should bring up the alert. I checked that answerrating.php does produce the letter a.
JQUERY:
$.post('../answerrating.php' , {answer_id: answer_id , direction: 2} , function(response){
if (response == 'a'){ //this line doenst work
alert("error");
}
else {
ratebox.text(response);
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您在响应中遇到一些空格,请尝试使用
jQuery.trim()
:您还可以使用
firebug
进行检查,以便您的响应不包含任何 html。如果您从服务器获取的不是纯文本,请尝试在调用中设置
dataType
:Perhaps you get some whitespaces in the response, try using
jQuery.trim()
:You could also use
firebug
to check so that your response don't include any html.If you are getting something other than plain text from the server try setting the
dataType
in your call: