duandaiqin6080 2016-11-10 17:30
浏览 57
已采纳

如何使用来自$ http.post的数据回调?

I'm trying to get my app run into my if statement but it went down to else statement which is not what I want. callback data is "Pass" which is correct for my if condition but it still ran down to else. Please take a look at my 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 to else statement
                            alert(data); <--- callback value is "Pass" which is match with my 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 INTO 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 INTO 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 the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the 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 from 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); // to 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 is Pass

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥20 怎么将vs中的程序同步到sql中的表中
      • ¥15 用flask框架接收前端上传的文本文件后怎么读取该文件
      • ¥15 有没有嵌入式ubuntu的朋友
      • ¥50 diddler Burp Suite
      • ¥20 关于UE5.1的问题,求专家解答!
      • ¥30 关于#爬虫#的问题:百度为您找到相关结果约100,000,000个 但只展现70页 有没有可能提取出来全部的搜索结果
      • ¥40 IIS部署API,弄了几天没弄出来,希望带佬远程帮我弄一下,有偿
      • ¥15 关于#c##的问题:winform中利用delegate更新ui的顺序错误
      • ¥15 qt5.6.1读取oracle8中文数据乱码
      • ¥15 matlab支持向量机预测部分遇到了问题