if else语句总是返回相同的值

时间:2017-03-02 21:49:18

标签: php if-statement

我是关于PHP和ajax的新手

Ajax返回数据==“确定”或数据==“否”取决于数据库中的电子邮件 但if-else块总是返回相同的值。它总是打印最后一个块,如“电子邮件可用!”我找不到错误。

<TreeView DataContext="{Binding}" ItemsSource="{Binding Scenes}">
    <TreeView.ItemTemplate>
        <HierarchicalDataTemplate ItemsSource="{Binding Path=Characters}"> 
                <TextBlock Text="{Binding Path=Name}"></TextBlock> 
            <HierarchicalDataTemplate.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=Name}"></TextBlock>
                </DataTemplate>
            </HierarchicalDataTemplate.ItemTemplate>
        </HierarchicalDataTemplate>
    </TreeView.ItemTemplate>
</TreeView>

public MainWindow()
{
    InitializeComponent();
    DataContext = new SceneViewModel(); 
}

3 个答案:

答案 0 :(得分:0)

尝试使用===代替==来比较字符串

答案 1 :(得分:0)

ajax

var email = "example@example.com";

$.ajax(
{
    type: 'post',
    url: 'check_email.php',
    data:
    {
        email: email,
    },
    success: callback
});


function callback(data)
{
    email_error = false;
    $("#email_error").css("display", "block");
    if (data == "OK")
    {
        $("#email_error").html("Email was already used!");
        $("#email_error").css("color", "#990000");
        $("#email_error").show();
        email_error = true;
    }
    else if(data =="NO")
    {
        $("#email_error").html("Email is available!");
        $("#email_error").css("color", "#F1F0D1");
        $("#email_error").show();
        email_error = false;
    }
}

html

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">

    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="check_email.js"></script>


    <title></title>
</head>
<body>

<div id="email_error">

</body>
</html>

php

<?php
echo "NO";

?>

答案 2 :(得分:0)

我在link中得到了一个简单的解决方案只有我用"OK"更改了"\r\nOK"

 $.ajax({
            type: 'post',
            url: 'check_email.php',
            data: {email:email,},
            success: callback});}
            function callback(data){
                email_error = false;    
                $("#email_error").css("display","block");
            if(data =="\r\nOK"){
                $("#email_error").html("Email was already used!");
                $("#email_error").css("color","#990000");               
                $("#email_error").show();
                email_error = true; 
            }else{
                $("#email_error").html("Email is available!");
                $("#email_error").css("color","#F1F0D1");
                $("#email_error").show();
                email_error = false;
                }           
            }