【发布时间】:2017-04-04 04:19:36
【问题描述】:
我正在尝试执行 Ajax POST 请求,结果是由echo 从 PHP 返回的。我刚刚注意到结果返回了另外两个未知字符。
这是我的 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";
}
?>
结果在这里
【问题讨论】:
-
不显示确切的 PHP 代码很难说。确定文件末尾没有任何内容?
-
文件末尾一定有什么东西或者存在编码问题...
-
从 PHP 文件末尾删除
?>。 -
@miken32 它有效。您能否简要解释一下并将其作为答案发布,以便我更好地理解
标签: javascript php jquery ajax echo