0

这是我在 jQuery 中的脚本:

$(document).ready(function() {
    $('input[type="submit"]').click(function() {
        event.preventDefault();

        var email = $('.email').val();

        $.ajax({
            type: "POST",
            url: "register_email.php",
            data: { "email": email },
            dataType: "json",
            success: function(data) {
                alert(data);
            },
            error: function(jqXHR, textStatus, errorThrown) {
                alert(textStatus + " " + errorThrown);
            }
        });
    });
});

它读取提交到变量的页面上的文本框的值email。我可以提醒它,它会显示出来。

但是,如果我asdou在框中输入类似内容并点击提交,我会收到此错误:

parsererror SyntaxError: JSON Parse error: Unexpected identifier "asdou"

我的 HTML 是:

<html>
    <head>
        <title>Syllable - iPhone Speed Reader</title>

        <link rel="stylesheet" href="styles/style.css">

        <script type="text/javascript" src="scripts/jquery-1.8.1.min.js"></script>
        <script type="text/javascript" src="scripts/jquery-ui-1.8.23.min.js"></script>
        <script type="text/javascript" src="scripts/scripts.js"></script>
    </head>
    <body>
        <div class="content">
            <img src="images/app-icon.png" alt="App icon">

            <h1>Syllable</h1>
            <p>Speed reading app for iPhone. Devour all your Instapaper and Pocket articles, and learn to read much faster in the process.</p>

            <form method="post" action="#">
                <input type="email" class="email" placeholder="Email me when it's live">
                <input type="submit" class="submit" value="Send">
            </form>

            <a href="http://twitter.com/syllableapp"></a>
        </div>
    </body>
</html>

我输入的内容有什么问题?如果有帮助,该页面在http://syllableapp.com/test上可见。我只是无法弄清楚我的 JSON 有什么问题。

4

0 回答 0