成功后,脚本不会从php获取数据到ajax脚本

时间:2017-10-01 08:40:16

标签: php jquery ajax

我真的不明白为什么这不起作用 - 我已经阅读了很多关于这个具体问题的内容,但我必须遗漏一些东西。

我想提醒" echo"来自PHP - 它没有。

AJAX:

$("#SaveChangesEmail").click(function() {
    var newemail = $("#mynewemail").val();
    $.ajax({
        type: "POST",
        url: "checkemail.php",
        data: {newemail:newemail},
        datatype: "json",
        success: function(data){
            alert(data);
        }
    });
});

PHP(checkemail.php)

    if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
        if($email == $row['myemail']){
            echo "This is your current email";
        }
        else if($email != $row['myemail']){
            $results = $con->query("
                UPDATE members SET 
                myemail='".$email."'
                WHERE m_id = '".$m_id."'") or die(mysqli_error($con));
            echo "Your email is changed";

        }
    } else {
        echo "Please provide a correct email";
    }

数据库正在更新,脚本本身是否运行完美,但在"成功后#34; - 它没有提醒任何事情。

更新

我现在试过这个:

AJAX:

$("#SaveChangesEmail").click(function() {
    var newemail = $("#mynewemail").val();
    $.ajax({
        type: "POST",
        url: "checkemail.php",
        data: {newemail:newemail},
        datatype: "text",
        success: function(data){
            if(data == 1) {
                alert("This is your current email");
            }
            else if(data == 2) {
                alert("Your email is changed");
            }
            else if(data == 3) {
                alert("Please provide a correct email");
            }
        }
    });
});

PHP(checkemail.php)

    if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
        if($email == $row['myemail']){
            echo "1";
        }
        else if($email != $row['myemail']){
            $results = $con->query("
                UPDATE members SET 
                myemail='".$email."'
                WHERE m_id = '".$m_id."'") or die(mysqli_error($con));
            echo "2";

        }
    } else {
        echo "3";
    }

控制台正在返回原始数据(1,2,3)但警报仍未显示!

0 个答案:

没有答案