2017-04-04 1 views
0

私はAjax POSTリクエストを実行しようとしています。結果はPHPからechoによって返されます。私は結果が2つの追加の未知の文字を返すことに気付いた。PHPエコーが2つの追加の未知の文字を返す

これは私のJavaScriptのである:

$.ajax({ 
      type: "POST", 
      url: "php/login.php", 
      data: loginDataString, 
      cache: false, 
      success: function(result){ 
       alert(result); 
       swal("Incorrect", result, "error"); 
      } 
     }); 

そして、私の全体のPHP

<?php 
$con = mysqli_connect("localhost","root","","EugeneStore"); 
if(!$con){ 
    die("Connection error: " . mysqli_error()); 
} 
if($_SERVER['REQUEST_METHOD']=='POST'){ 
     $UN = $_POST['login_username']; 
     $PW = $_POST['login_password']; 
     date_default_timezone_set('Asia/Manila'); 
     $t=time(); $timeDAY = date('d',$t); $timeMONTH = date('m',$t); $timeYEAR = date('Y',$t); $timeYEAR2 = date('y',$t); $CURRENTDATE = "$timeDAY/$timeMONTH/$timeYEAR"; $a2 = date('H',$t); $a3 = date('i',$t); $ampm = ""; 
        if ($a2 >= 0 && $a2 <= 11){ 
         $ampm = "AM"; 
        } 
        if ($a2 >= 12 && $a2 <= 23){ 
         $ampm = "PM"; 
        } 
        if ($a2 == 13){ 
         $a2 = 1; 
        } 
        if ($a2 == 14){ 
         $a2 = 2; 
        } 
        if ($a2 == 15){ 
         $a2 = 3; 
        } 
        if ($a2 == 16){ 
         $a2 = 4; 
        } 
        if ($a2 == 17){ 
         $a2 = 5; 
        } 
        if ($a2 == 18){ 
         $a2 = 6; 
        } 
        if ($a2 == 19){ 
         $a2 = 7; 
        } 
        if ($a2 == 20){ 
         $a2 = 8; 
        } 
        if ($a2 == 21){ 
         $a2 = 9; 
        } 
        if ($a2 == 22){ 
         $a2 = 10; 
        } 
        if ($a2 == 23){ 
         $a2 = 11; 
        } 

     $CURRENTTIME = "$a2:$a3 $ampm"; 

     $sql = "SELECT * FROM Users WHERE Username='".$UN."' AND Password='".$PW."'"; 
     $result = mysqli_query($con,$sql); 
     $count = mysqli_num_rows($result); 
     if($count==1) { 
      $rows00 = mysqli_fetch_array($result); 
      if($rows00['UserType'] == "Admin") { 
       $ADDSYSREC = mysqli_query($con, "INSERT INTO SystemLogs(Username, Date, Time, Information, Type) 
       VALUES('".$rows00['Username']."', '".$CURRENTDATE."', '".$CURRENTTIME."', '".$rows00['Username']." Logged into the system', 'Admin')"); 
       echo "Login Correct Admin"; 

      } 
      if($rows00['UserType'] == "Member") { 
       $ADDSYSREC = mysqli_query($con, "INSERT INTO SystemLogs(Username, Date, Time, Information, Type) 
       VALUES('".$rows00['Username']."', '".$CURRENTDATE."', '".$CURRENTTIME."', '".$rows00['Username']." Logged into the system', 'Member')"); 
       echo "Login Correct Member"; 

      } 
     } else {  
      echo 'Wrong username or password'; 
     } 
} else { 
    echo "Something is wrong with the system. Try again Later"; 
} 
?> 

そしてここ

enter image description here enter image description here

+0

正確なPHPコードを表示せずに言うのは難しいです。ファイルの最後には何もありませんか? –

+0

ファイルの最後に何かがあるか、エンコードの問題がある... – Zeke

+0

PHPファイルの最後から '?>'を削除します。 – miken32

答えて

2

結果あなたはPHPのみのファイルがあるとき、あなたは閉鎖を外すべきですg ?>タグ。 This questionにはいくつかの説明がありますが、大きな理由はWebサーバーが空白や隠れた文字を出力しないようにするためです。