Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 相等运算符在jquery中不起作用_Php_Jquery_Codeigniter - Fatal编程技术网

Php 相等运算符在jquery中不起作用

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=

我最近开始在codeigniter中工作,我正在尝试通过jquery进行数据验证。我将文本框中输入的电子邮件发送给控制器,它会发送“exist”或“notexist”作为回报。现在,当我尝试比较结果时,在这两种情况下,它总是转到其他。我不明白为什么会这样? 如果我有错误,请纠正我。提前准备好

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");