Php 相等运算符在jquery中不起作用
我最近开始在codeigniter中工作,我正在尝试通过jquery进行数据验证。我将文本框中输入的电子邮件发送给控制器,它会发送“exist”或“notexist”作为回报。现在,当我尝试比较结果时,在这两种情况下,它总是转到其他。我不明白为什么会这样? 如果我有错误,请纠正我。提前准备好Php 相等运算符在jquery中不起作用,php,jquery,codeigniter,Php,Jquery,Codeigniter,我最近开始在codeigniter中工作,我正在尝试通过jquery进行数据验证。我将文本框中输入的电子邮件发送给控制器,它会发送“exist”或“notexist”作为回报。现在,当我尝试比较结果时,在这两种情况下,它总是转到其他。我不明白为什么会这样? 如果我有错误,请纠正我。提前准备好 if (pattern.test(user_name)) { $.post('http://localhost/index.php/user/checkuseremail', 'user_name=
if (pattern.test(user_name)) {
$.post('http://localhost/index.php/user/checkuseremail', 'user_name=' + user_name, function(datar) {
console.log(datar);
if (datar.toString() === "exist") {
alert('Email Exists');
}
else {
alert('Valid email.');
}
});
}
在“localhost/index.php/user/checkuseremail”中:
第页:
$.post('http://localhost/index.php/user/checkuseremail', 'user_name=' + user_name, function(datar) {
console.log(datar);
if (datar.result == "exist") {
alert('Email Exists');
}
else {
alert('Valid email.');
}
},"json");
datar
的值是多少?如果该值设置正确,则可以正常工作:。我猜你的值周围有一些空白。尝试使用$.trim
。如果电子邮件已经存在,它将获得“exist”,否则它将获得“notexist”。我已经记录了它,并且它在不同的情况下记录了这两个值,但是警报总是显示“有效电子邮件”。您可以调整该值并查看console.log(datar,datar.trim()=='exist')代码>@Massab你能给出你得到的确切回答吗?我们在这里提问会得到“反对票”吗?????
$.post('http://localhost/index.php/user/checkuseremail', 'user_name=' + user_name, function(datar) {
console.log(datar);
if (datar.result == "exist") {
alert('Email Exists');
}
else {
alert('Valid email.');
}
},"json");