这个jQuery AJAX回调有什么问题?

Xor*_*rty 0 html ajax jquery json jquery-mobile

我正在创建移动webapp的前端,但我还不想使用后端语言.

  • 这将是宁静的
  • 我在嘲笑JSON.当我想检查人是否有效时,我会使用"check/123"这样的地址
  • 我在我的文件系统中创建了文件夹,模拟了模拟JSON响应的宁静链接和文件.所以我有一个名为"check"的目录和里面的文件"123",内容如下:

    {"存在":"是"}

现在,这是我的整个页面,以便您可以重现问题,即始终警告错误:

<!DOCTYPE html>
<html>
<head>
    <!-- meta info -->
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" /> 
    <!-- .js files -->
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script> 
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js"></script> 
</head>

<body>
    <div data-role="content"> 
        <form id="form_check_person">
            <div data-role="fieldcontain">
                <input type="text" id="person_id" name="person_id" value="" />
            </div>
            <div data-role="fieldcontain">
                <input type="submit" value="Check me" />
            </div>
        </form>
        <script type="text/javascript">
            $("#form_check_person").submit(function() { 
                $.ajax({ 
                    url: "check/" + $("person_id"),
                    type: "GET",
                    dataType: "json",

                    success: function() {
                        alert('success');
                    },

                    error: function() {
                        alert('error');
                    }
                });
            });
        </script> 
    </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

编辑:

我已经添加.val()#{'#person_id'},并仍然得到错误:/

Kan*_*iya 7

我不知道你在做什么$("person_id").试试这个:

$("#person_id").val();
Run Code Online (Sandbox Code Playgroud)