在Win Phone 8.1中的Cordova应用程序支持环境

时间:2015-04-02 07:15:50

标签: php html cordova windows-phone-8.1 google-cloud-sql

我是Phone GAP的新手,想要从PHP部署我的移植APP,谷歌CloudSQL赢得手机商店8.1。我使用具有以下要求的cordova开发了一个Web应用程序

前端:PhoneGap(Cordova) - HTML,JQUERY(给定在线jquery支持链接)。

后端:使用Jquery AJAX Call通过PHP访问Google Cloud SQL。

对于Win Phone 8.1支持,我需要在Win Phone App Store中上传。

我是否应该使用Phone Gap for Win Mobile或任何其他技术,因为我希望此应用程序部署在Win Phone Store中并在Win Phone 8.1中使用。

示例脚本:

1.index.html

<!DOCTYPE html>
<html>
    <head>
        <title>sample phonegap</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <!-- online jquery support links -->

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<!-- script for request page -->

 <script type="text/javascript" src="request.js"></script>

</head>
<body>
<div id="landmark-1" data-landmark-id="1">
    <form method="post">
        <label for="email"> // Email id as input
            <b>Email</b>
            <input type="email" id="email" name="email">
        </label>
        <label for="comment">// comments as input
            <b>Comment</b>
            <textarea id="comment" name="comment" cols="30" rows="10"></textarea>
        </label>
        <input type="submit" value="Save" id="save">
    </form>
</div>
</body>
</html>
  1. 用户通过AJAX请求发送到后端的输入到PHP页面。
  2. request.js

        $(document).ready(function() {
           $('form').submit(function(){
    
                var landmarkID = $(this).parent().attr('data-landmark-id');
                var postData = $(this).serialize();
                $.ajax({
                    type: 'POST',
                    url: "save.php",
                    data: postData+'&lid='+landmarkID,
                    success: function(data)
                    {
                        alert(JSON.parse(data));
                        $('form')[0].reset();
                    },
                    error: function(data){
                        alert('There was an error adding your comment'+JSON.stringify(data));
                    }
                });
    
    return false;
            });
        });
    

    3.在PHP页面中,用户提供的输入保存在Google Cloud SQL中。

    save.php

    <?php
    
    **//connection parameters**
    
    $server = "IP";
    
    $username = "";
    
    $password = "";
    
    $database = "";
    
    $con=new mysqli($server,$username,$password,$database); **//connect to db**
    
    $locationID = $_POST["lid"];
    
    $email = mysqli_real_escape_string($con,$_POST["email"]);
    
    $comment = mysqli_real_escape_string($con,$_POST["comment"]);
    
    $sql = "INSERT INTO comments (location_id, email, comment) "; **//insert values in table**
    
    $sql .= "VALUES ($locationID, '$email', '$comment')";
    
    $result="";
    
    if (!mysqli_query($con,$sql)) {
    
        die('Error: ' . mysqli_error($con));
    
    } else {
            $result="SUCCESS";
    }
    
    echo json_encode($result);  **//return result to front end**
    
    ?>
    

    创建表格查询:

    表名:评论

    CREATE TABLE `comments` (
      `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `location_id` int(11) DEFAULT NULL,
      `email` varchar(45) DEFAULT NULL,
      `comment` text,
      PRIMARY KEY (`id`)
    )
    

    上面的编码过程是否正确以支持Win App,我可以知道在Win Store中上传的步骤吗?

    在Win Store成功上传后,这会在Win Phone 8.1中运行吗?有人会提供示例脚本来支持Win phone 8.1吗?

1 个答案:

答案 0 :(得分:0)

我不确定您是否已经解决了这个问题。

我建议坚持使用Phonegap。我会将save.php文件放在服务器上的某个位置,而不是将其与您的应用程序捆绑在一起。 PHP无法在phonegap应用程序中运行,因此您必须将其与应用程序文件保持在外部。只需将ajax语句的“url:”部分中的url更改为save.php所在的完整URL。