0

This code is making my head explode since i dont find an explanation to it, my jquery .ajax has this code:

$.ajax({
        type: "POST",
        url: "/xt/processtrivia.php",
        data: "mail="+email,
        success: function(r){
                //alert(r);  printed answer, its ok
                //var xx = typeof r; it return a string...
                var r1 = r;
                if(r == "existe"){ //this part is failing for no reason :/ even if the value returned by the php file is correct
                  alert("email exists");
                }
        }
        });

and in my processtrivia.php is this code:

$mail = $_POST['mail'];
$sql ="select * from trivia where email='" .$mail ."'";

$rs = $modx->prepare($sql);
$rs->execute();

if($rq= $rs->fetch(PDO::FETCH_ASSOC)){
  return "existe";
}
else{
  return "noexiste";
}

with just a query to the DB to check if an email exists, the php file is showind data (existe or noexiste) correctly, so its not my php file, my problem is with that success thing, even if the email exist, it doesnt show the alert "email exists" message.

hope u can help me guys, this is my first time doing .ajax requests...

thanks

4

2 回答 2

1

change

return "existe";

to

echo "existe";
于 2013-06-28T19:44:55.707 回答
0

Your php code must print/echo the "existe" / "noexiste" string and not return them, unless the code snippet you showed us is inside a function that is being printed.

if($rq= $rs->fetch(PDO::FETCH_ASSOC)){
  print "existe";
}
else{
  print "noexiste";
}
于 2013-06-28T19:44:28.340 回答