Phonegap无法在设备中工作,但在浏览器中工作

时间:2014-04-13 06:12:47

标签: android cordova

我正在练习一个phonegap应用程序。在浏览器中工作的功能无法在设备中运行。我在这里给出了代码。

reg.html

    <!DOCTYPE html>
<html>
  <head>
    <title>Daily Word</title>
    <script type="text/javascript" charset="utf-8" src="../js/cordova.js"></script>
    <script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="../js/jquery.mobile.js"></script>
    <script src="http://debug.phonegap.com/target/target-script-min.js#anonymous"></script>
    <link rel="stylesheet" href="../css/jquery.mobile.css" type="text/css"/>
    <link rel="stylesheet" href="../css/style.css" type="text/css"/>
    <script type="text/javascript">
    $("#RegPage").live( 'pageinit' , function (event) {
        $("#btnSignUp").live( 'click', function(){
            var uname=$('.Username').val();
            var pwd=$('.Password').val();
            var email=$('.Email').val();
            alert("check");
            $.ajax({
                url:"http://mysite.in/DailyWord/login.php?Username="+uname+"&Password="+pwd,
                type:"get",
                datatype:"html",
                success: function(response){
                    if( response == "Admin" )
                        {
                            $.mobile.changePage("Admin/admin_home.html",{ transition: "slidedown", changeHash: false  });   
                        }
                    else if( response == "User" )
                        {
                            $.mobile.changePage("User/index.html",{ transition: "slidedown", changeHash: false  }); 
                        }
                    else
                        {
                            alert(response);
                        }
                }
            });
        });   
    });
    </script>
  </head>
  <body>
    <div data-role="page" id="RegPage">
        <div data-role="header" id="header"><h4>Daily Word</h4></div>
        <div data-role="content">
        <form>
        <fieldset>
        <input type="text" name="Username" class="Username" id="text-basic" value="Username" onfocus="if (this.value == 'Username') this.value = '';" onblur="if (this.value == '') this.value = 'Username';">
        <input type="password" name="Password" class="Password" id="text-basic" value="Password" onfocus="if (this.value == 'Password') this.value = '';" onblur="if (this.value == '') this.value = 'Password';">
        <input type="text" name="Email" class="Email" id="text-basic" value="Email" onfocus="if (this.value == 'Email') this.value = '';" onblur="if (this.value == '') this.value = 'Email';">
        <input type="button" value="Sign Up" name="btnLogin" id="btnSignUp">
        <input type="reset" value="Reset" name="btnClear">
        </fieldset>
        </form>
        </div>
        <div data-role="footer" data-position="fixed" id="footer" ><h4><a href="http://eazytutor.in/Mobile/">EazyTutor</a></h4></div>
    </div>
  </body>
</html>

在同一目录下的其他文件中使用相同的代码,但此处不起作用。任何人都可以提供帮助吗?

警报本身无效...

1 个答案:

答案 0 :(得分:0)

我通过在div页面中添加脚本来实现这一点。我的正确代码如下。

<!DOCTYPE html>
<html>
  <head>
    <title>Daily Word</title>
    <script type="text/javascript" charset="utf-8" src="../js/cordova.js"></script>
    <script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="../js/jquery.mobile.js"></script>
    <script src="http://debug.phonegap.com/target/target-script-min.js#anonymous"></script>
    <link rel="stylesheet" href="../css/jquery.mobile.css" type="text/css"/>
    <link rel="stylesheet" href="../css/style.css" type="text/css"/>

  </head>
  <body>
    <div data-role="page" id="RegPage">
        <div data-role="header" id="header"><h4>Daily Word</h4></div>
        <div data-role="content">
        <form>
        <fieldset>
        <input type="text" name="Username" class="Username" id="text-basic" value="Username" onfocus="if (this.value == 'Username') this.value = '';" onblur="if (this.value == '') this.value = 'Username';">
        <input type="password" name="Password" class="Password" id="text-basic" value="Password" onfocus="if (this.value == 'Password') this.value = '';" onblur="if (this.value == '') this.value = 'Password';">
        <input type="text" name="Email" class="Email" id="text-basic" value="Email" onfocus="if (this.value == 'Email') this.value = '';" onblur="if (this.value == '') this.value = 'Email';">
        <input type="button" value="Sign Up" name="btnLogin" id="btnSignUp">
        <input type="reset" value="Reset" name="btnClear">
        </fieldset>
        </form>
        </div>
        <div data-role="footer" data-position="fixed" id="footer" ><h4><a href="http://eazytutor.in/Mobile/">EazyTutor</a></h4></div>

<script type="text/javascript">
    $("#RegPage").live( 'pageinit' , function (event) {
        $("#btnSignUp").live( 'click', function(){
            var uname=$('.Username').val();
            var pwd=$('.Password').val();
            var email=$('.Email').val();
            alert("check");
            $.ajax({
                url:"http://mysite.in/DailyWord/login.php?Username="+uname+"&Password="+pwd,
                type:"get",
                datatype:"html",
                success: function(response){
                    if( response == "Admin" )
                        {
                            $.mobile.changePage("Admin/admin_home.html",{ transition: "slidedown", changeHash: false  });   
                        }
                    else if( response == "User" )
                        {
                            $.mobile.changePage("User/index.html",{ transition: "slidedown", changeHash: false  }); 
                        }
                    else
                        {
                            alert(response);
                        }
                }
            });
        });   
    });
    </script>
    </div>
  </body>
</html>