Muhammed
Muhammed

Reputation: 27

ajax success method fallback type does not work

action page return type is x in php but success else happens

 $.ajax({
        url: "user.php?mysts=chck",
        type: "POST",
        data: $("#cntstngfrm").serialize(),
        success: function (cevap) {
            console.log("myrequest =  "+cevap);
            if (cevap == "x") {
                alert("dasdasd");
            }else{
               alert("999");
            }
        }
 });

user.php :

if (isset($_GET['mysts'])=="chck"){
     $duzenle=$db->prepare("UPDATE mmb SET
        mmbss=:mmbss

        WHERE id={$_POST['wqrid']}");

    $control=$duzenle->execute(array(
        'mmbss'=>$_POST['mmbss']
    ));
    if ($control) {
        echo "x";
    }else{
        echo "y";
    }
}

console : enter image description here

everything ok but it gives alert 999. Thansk for help.

Upvotes: 1

Views: 46

Answers (1)

uingtea
uingtea

Reputation: 6524

based on your second images, there is a newline \n character, use .trim() to remove it

success: function (cevap) {
  console.log("myrequest =  " + cevap);
  cevap = cevap.trim(); // <= remove space or newline
  if (cevap == "x") {
    alert("dasdasd");
  }
  else {
    alert("999");
  }
}

or check again user.php and make sure there are no another echo

Upvotes: 1

Related Questions