我明白了
Uncaught SyntaxError: Unexpected token < x.extend.parseJSON jQuery.js:4
$.ajax.success Login.js:15
c jQuery.js:4
p.fireWith jQuery.js:4
k jQuery.js:6
r
jQuery 是新下载的,我的登录 js 错误在这一行
var json = jQuery.parseJSON(data);
编辑这里是登录 php 页面,如果您需要 javascript,请告诉我。您是否还会说这比设置标准表单和页面更有效:
<?php
require("./../config.php");
if (!isset($_POST['req']))
{
die("No request provided.");
}
else
{
if ($_POST['req'] == "login")
{
$json = array("success"=>false, "msg"=>"", "req"=>"login");
if (!isset($_POST['user']) || empty($_POST['user']))
{
$json['success'] = false;
$json['msg'] = "No user provided";
}
else
{
if (!isset($_POST['pass']) || empty($_POST['pass']))
{
$json['success'] = false;
$json['msg'] = "No password provided";
}
else
{
$user = mysql_real_escape_string($_POST['user']);
$password = mysql_real_escape_string($_POST['pass']);
$password = hash("sha512", $password);
$query = mysql_query("SELECT `id` FROM `users` WHERE `username` = '" . $user . "' AND `password` = '" . mysql_real_escape_string($password) . "' LIMIT 1");
if (mysql_num_rows($query))
{
$sessID = mysql_real_escape_string(session_id());
$hash = mysql_real_escape_string(hash("sha512", $sessID.$_SERVER['HTTP_USER_AGENT']));
$userData = mysql_fetch_assoc($query);
$expires = time() + (60 * 15);
mysql_query("INSERT INTO `active_users` (`user`, `session_id`, `hash`, `expires`) VALUES (" . (int) $userData['id'] . ", '" . $sessID . "', '" . $hash . "', " . $expires . ")");
$json['success'] = true;
$json['msg'] = "Logged in";
}
else
{
$json['success'] = false;
$json['msg'] = "Username or password are incorrect.";
}
}
}
print(json_encode($json));
}
}
?>