javascript - How to use if with data callback from $http.post? -


i'm trying app run if statement went down else statement not want. callback data "pass" correct if condition still ran down else. please take @ code.

js file

$http.post(path, postdata                 ).success(function (data, status, headers, config) {                     //if (data) {                         // $scope.postdataresponse = data;                        if (data === "pass"){                          setcookie("username", $scope.formdata.username);                         setcookie("cafe_id", $scope.formdata.cafe_id);                         console.log(getcookie("username"));                          alert("ลงทำเบียนสำเร็จ !");                            $location.url('/viewsavecafedetail');                         //console.log(data);                         //alert("สมัครสมาชิกสำเร็จ");                           //$scope.insertcafe();                         //$scope.sendemail();                         //  $scope.reset();                         //  $scope.getdata();                             }else{ <--- ran down else statement                             alert(data); <--- callback value "pass" match if condition.                         } 

php file

<?php header("access-control-allow-origin: *");     header("access-control-allow-credentials: true");     header("access-control-allow-methods : get,post,put,delete,options"); header('access-control-allow-headers: origin, content-type, accept, authorization, x-requested-with, x-your-custom-header');     header("content-type : application/json");         header("accept : application/json");  $servername = "localhost";     $username = "root";     $userpassword = "";     $dbname = "middlework";      $conn = new mysqli($servername,$username,$userpassword,$dbname);     mysqli_set_charset($conn,"utf8");     session_unset(); session_start();    $postdata = file_get_contents("php://input"); $request = json_decode($postdata); $strsql = "insert users "; $strsql .="(username,password,firstname,lastname,email,tel,accountstat,verifycode,verifystat) "; $strsql .="values "; $strsql .="('".$request->username."','".$request->password."','".$request->firstname."' "; $strsql .=",'".$request->lastname."','".$request->email."','".$request->tel."','user','".session_id()."','none' ) ";    mysqli_query($conn,$strsql) or die(mysqli_error($conn));      $insertcafe = "insert cafe (cafe_id,username,cafename) values ('1' , '".$request->username."', '".$request->cafename."')";  require_once('phpmailer/phpmailerautoload.php');         $mail = new phpmailer(); $mail->ishtml(true); $mail->charset = "utf-8"; $mail->issmtp(); $mail->smtpauth = true; // enable smtp authentication $mail->smtpsecure = "ssl"; // sets prefix servier $mail->host = "smtp.gmail.com"; // sets gmail smtp server $mail->port = 465; // set smtp port gmail server $mail->username = "kitsakorn.p55@rsu.ac.th"; // gmail username $mail->password = "1100501068349"; // gmail password $mail->from = "kitsakorn.p55@rsu.ac.th"; // "name@yourdomain.com"; $mail->fromname = "thaicoffeeshoponline";  // set name $mail->subject = "ยืนยันการสมัครสมาชิก thaicoffeeshoponline";                             $mail->body = "ขอขอบคุณที่สมัครเป็นสมาชิกกับเรา กรุณาคลิก url ด้านล่างเพื่อทำการ activate บัญชีของคุณ</br>                http://localhost/activate.php?sid=".session_id()."&uid=".$request->username."</br></br> thaicoffeeshop.com";     $mail->addaddress($request->email); // address  if($conn->query($insertcafe)) {     if (!$mail->send()) {     //echo "ไม่สามารถส่ง email: " . $mail->errorinfo;     echo "emailfail"; } else {     echo "pass ";     //json_decode(); }     //echo "save cafe done.[".$insertcafe."]";  } else {     echo "";     //echo mysqli_error($conn);     //echo "ไม่สามาถบันทึกข้อมูล[".$insertcafe."]"; }    $conn->close(); ?> 

value pass

your php file has echo "pass "; writes "pass" followed space comparing against string "pass" without space.

in addition, might have blank line @ end of php file included in output. can worked around removing ?> tag end.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -