1

我使用 HTML5/Javascript/JqueryAjax 制作了基于 Web 的应用程序。托管的 url 工作正常,但是当我使用 phonegap 2.8.1 在 windows phone 7 中运行它时,它没有运行。它调用错误函数。

这是我的代码:

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

    <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" />
        <meta charset="utf-8">
        <title></title>
        <!-- CSS -->
        <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
        <link rel="stylesheet" href="assets/css/style.css">     
        <script type="text/javascript" charset="utf-8" src="cordova-2.8.1.js"></script>
        <script type="text/javascript" src="assets/js/jquery-1.8.3.min.js"></script>
        <script type="text/javascript">

    document.addEventListener("deviceready", onDeviceReady, false);


    function signclick() {


        var validate = true;
        var usv = document.getElementById('username').value;
        var psv = document.getElementById('password').value;
        var emv = document.getElementById('email').value;
        if (usv == '') {
            if (psv != '') {
                document.getElementById('validatepass').innerHTML = "";
            }
            if (emv != '') {
                document.getElementById('validateemail').innerHTML = "";
            }
            document.getElementById('validateuser').innerHTML = " - Please Enter a User Name";
            validate = false;
        }
        if (emv == '') {
            if (usv != '') {
                document.getElementById('validateuser').innerHTML = "";
            }
            if (psv != '') {
                document.getElementById('validatepass').innerHTML = "";
            }
            document.getElementById('validateemail').innerHTML = " - Please Enter Email ID";
            validate = false;
        }
        if (psv == '') {
            if (usv != '') {
                document.getElementById('validateuser').innerHTML = "";
            }
            if (emv != '') {
                document.getElementById('validateemail').innerHTML = "";
            }
            document.getElementById('validatepass').innerHTML = " - Please Enter a Valid Password";
            validate = false;
        }
        if (usv != '' && psv != '' && emv != '') {
            document.getElementById('validateuser').innerHTML = "";
            document.getElementById('validateemail').innerHTML = "";
            document.getElementById('validatepass').innerHTML = "";
            var make = { "Email": emv, "Username": usv, "Password": psv };

            $.ajax({
                type: "POST",
                url: create_user,
                data: JSON.stringify(make),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    window.location = "Login.html";
                },
                error: function (error) {
                    $("#alert").show();
                    document.getElementById('alert').innerHTML = "<b>Connection Failed!</b> Please Check Your Configurations";
                }
            });
        }


    }


</script> 

    </head>

    <body>
<div class="container">
        <div class="header">

                <div class="row">
                    <div class="logo span4">
                    <a href="http://www.texpoglobal.com"><img src="assets/img/texpo.png" width="70" height="70" align="left" style="margin-left:15px;margin-top:8px;"/></a>

                    </div>
                    <div class="links span8">
                        <a class="home" href="index.html" rel="tooltip" data-placement="bottom" data-original-title="Home"></a>
                    </div>
                </div>
            </div>


        <div class="register-container container">
            <div class="row">

                <div class="register span6" style="min-width:230px;">
                    <form action="" method="post">
                        <h2>REGISTER TO <span class="red"><img src="assets/img/texpo2.png"  width="90px" height="60px" /> </span></h2>
                         <div id="alert" style="display:none;"class="alert alert-error"></div>
                        <label for="username">Username<span id="validateuser" class="valid" ></span></label>
                        <input type="text" id="username" name="username" placeholder="choose a username..." required>
                        <label for="email">Email<span id="validateemail" class="valid" ></span></label>
                        <input type="text" id="email" name="email" placeholder="enter your email..." required>
                        <label for="password">Password<span id="validatepass" class="valid" ></span></label>
                        <input type="password" id="password" name="password" placeholder="choose a password..." required>
                        <button type="button" onclick="signclick()" >REGISTER</button>


                    </form>
                </div>
            </div>
        </div>
</div>
        <!-- Javascript -->
        <script src="assets/js/jquery-1.8.2.min.js"></script>
        <script src="assets/bootstrap/js/bootstrap.min.js"></script>
        <script src="assets/js/jquery.backstretch.min.js"></script>
        <script src="assets/js/scripts.js"></script>
        <script src="assets/js/config.js"></script>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript">
            app.initialize();
        </script>
    </body>

</html>

我真的不知道是什么问题。它适用于Android,但不适用于Windows Phone。任何帮助,将不胜感激。

4

1 回答 1

1

问题解决了!!!!

我只需要在通话$.support.cors = true;前添加$.ajax。问题是我WebService从跨平台发布信息。

以下是代码:

$.support.cors = true;
    $.ajax({
                    type: "POST",
                    url: create_user,
                    data: JSON.stringify(make),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (result) {
                        window.location = "Login.html";
                    },
                    error: function (error) {
                        $("#alert").show();
                        document.getElementById('alert').innerHTML = "<b>Connection Failed!</b> Please Check Your Configurations";
                    }
                });

我不知道这是否是好的做法,但它对我有帮助。玩得开心编码。

于 2013-06-26T10:48:49.257 回答