当服务器端脚本使用SQLite3命令时,对POST没有响应

时间:2016-02-14 12:50:28

标签: javascript php jquery ajax sqlite

我正在使用AJAX将表单的内容发布到Web服务器。客户端脚本应在收到响应时显示警报。当服务器端的PHP脚本仅包含回显时,将显示警报。当PHP脚本包含SQLite3命令时,不会显示警报。

Web服务器是Apache2。

HTML和客户端脚本:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Register</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <link href='http://fonts.googleapis.com/css?family=Nunito:400,300' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="login_style.css">
</head>

<body>
    <script>
    function register() {
        var emailAddress = document.getElementById("mail").value;
        $.post(
            "register.php",
            {email: emailAddress},
            function(response) {
                alert(response);
            });
    }
    </script>

    <h1>Register</h1>
    <label for="mail">Email:</label>
    <input type="email" id="mail">
    <label for="password">Password:</label>
    <input type="password" id="password">
    <button type="submit" onclick="register()">Register</button>
</body>
</html>

服务器端PHP:

<?php
$db = new SQLite3('user.db'); // The problem line.
printf("Response!\n");
?>

“ls -l”/ var / www / html / editor目录的输出(包含文件):

total 12
-rw-r--r-- 1 root root 1922 Feb 14 12:36 login_style.css
-rw-r--r-- 1 root root  878 Feb 14 12:36 register.html
-rw-r--r-- 1 root root   65 Feb 14 12:36 register.php
-rw-rw-rw- 1 root root    0 Feb 14 12:36 user.db

有趣的是,当我在/ var / www / html / editor目录中在命令行上手动运行命令“php5 register.php”时,脚本将回显“Response!”我是否注释掉SQLite3行。

非常感谢任何帮助。

0 个答案:

没有答案