我的代码适用于除一个以外的所有文件。它会在
处引发unexpected token
错误
data = $.parseJSON(msg);
我真的不知道是什么导致了这个问题......
使用Javascript:
function submitform() {
var pass = document.getElementById("password").value;
var nologinsession = document.getElementById("Username");
if (nologinsession == null) {
var userid = "<?php echo $_SESSION['SESS_MEMBER_ID']; ?>";
var username = "none";
} else {
var username = document.getElementById("Username").value;
var userid = "none";
}
$.ajax({
type: "POST",
url: "php/call.php",
data: { pass: pass, username: username, userid: userid }
}).done(function( msg ) {
data = $.parseJSON(msg);
var permission = data['permission'];
var reason = data['reason'];
if (permission == 'okay') {
location.reload;
} else if (permission == 'nope') {
alert(reason);
} else {
alert('There appears to be something wrong. Beam me up, Scotty.');
}
});
};
call.php :
<?php
//Start session
session_start();
//Include database connection details
require_once('Connection.php');
$password = $_POST['pass'];
$username = $_POST['username'];
$userid = $_POST['userid'];
$requester = $_POST['requester'];
$permission;
$reason;
if($userid == 'none') {
$query = "SELECT something FROM table WHERE email='$username'";
// the result of the query
$query = mysql_query("$query") or die("Invalid query: " . mysql_error());
$row = mysql_fetch_assoc($query);
$result = $row["something"];
if($result == $password) {
$permission = 'okay';
$reason = 'empty';
} else {
$permission = 'nope';
$reason = 'Password is incorrect.';
}
} else {
$query = "SELECT something FROM table WHERE ID='$userid'";
// the result of the query
$query = mysql_query("$query") or die("Invalid query: " . mysql_error());
$row = mysql_fetch_assoc($query);
$result = $row["something"];
if($result == $password) {
$permission = 'okay';
$reason = 'empty';
} else {
$permission = 'nope';
$reason = 'Password is incorrect.';
}
};
$json['permission'] = $permission;
$json['reason'] = $reason;
print(json_encode($json));
?>
修正了一些评论后让我走上正轨:
原来这是建立数据库连接的问题。将新IP地址放在白名单上,问题就是修复。谢谢你们!