我的Cordova代码不会工作AJAX呼叫

时间:2013-02-08 16:04:07

标签: jquery ajax cordova

我不知道发生了什么事!我的cordova项目不会让我从我的ajax调用中获取数据!我正在尝试为服务器调用用户身份验证,但现在,我所关注的只是将数据发送到服务器并让它回来发出警报。我该怎么做!

HTML,JS,jQuery

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi">
    <title>Hello World</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js" type="text/javascript">

    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("form").submit(function () {

                var uname = document.getElementById("username").value;
                var pword = document.getElementById("password").value;
                var postData = {
                    username: uname,
                    password: pword
                };

                $.ajax({
                    url: "http://www.yellowcabsavannah.com/test.php",
                    type: "POST",
                    data: postData,
                    async: false,
                    dataType: 'json',
                    contentType: 'json',
                    cache: false,
                    success: function (data) {
                        var d = JSON.parse(data);
                        alert(d);
                    }
                });
                return false;
            });
        });
    </script>
</head>

<body>
    <form action="">
        <input type='text' id="username" name="username" placeholder="Username">
        <br>
        <input type='password' id="password" name="password" placeholder="password">
        <br>
        <input type="submit" id="submit" value="Login">
    </form>
</body>

PHP

echo json_encode(array("username" => $_POST["username"], "password" => $_POST["password"]));

0 个答案:

没有答案