Как разместить данные в приложении Cordova с помощью PHP и MongoDB

0

Я новичок в приложении cordova. Я хочу спросить вас о том, как публиковать данные из формы в приложении cordova, используя php и MongoDB. У меня есть index.html в приложении cordova и comment.php в c: /xampp/htdocs. Я хочу отображать данные в comment.php из index.html. Вот код. это index.html и comment.php

index.html

<!DOCTYPE html> 
<html>
    <head>
        <title>jQM Complex Demo</title> 
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/> 
        <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/> 
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" /> 
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script> 
        <script>
            $.ajax({ 
                type : "POST", 
                url : "comment.php", 
                crossDomain: true,
                beforeSend : function() {$.mobile.loading('show')}, 
                complete : function() {$.mobile.loading('hide')}, 
                data : {email : 'email', comment : 'comment'}, 
                dataType : 'json', 
                success : function(response) { 
                    //console.error(JSON.stringify(response)); 
                    alert('Works!');
                }, 
                error : function() { 
                    //console.error("error"); 
                    alert('Not working!'); 
                } 
            }); 
        </script>
    </head> 
    <body>
        <script>
            document.addEventListener( "deviceready", function () {
                new kendo.mobile.Application( document.body, {
                    statusBarStyle: "black-translucent"
                });
            }, false );
        </script>
        <div data-role="page" id="index"> 
            <div data-theme="b" data-role="header"> 
                <h1>Index page</h1> 
            </div> 
            <div data-role="content"> 
            </div> 
        </div> 
    </body> 
</html>

Comment.php

  $email = isset($_POST['email']) ? $_POST['email'] : '';
    echo $email; 
    $comment = isset($_POST['comment']) ? $_POST['comment'] : '';
    echo $comment; 
Теги:
cordova

2 ответа

0

В командной строке проверьте свой IP-адрес

IPCONFIG

Ethernet adapter Local Area Connection:

   Connection-specific DNS Suffix  . : 
   Link-local IPv6 Address . . . . . : fe80::19a7:4cc9:c1e8:f9ef%11
   IPv4 Address. . . . . . . . . . . : 192..168.one.three 
   Subnet Mask . . . . . . . . . . . : 255 .255 .254 .0
   Default Gateway . . . . . . . . . : 192 .168 .1 .1

Теперь ваш ip-адрес сервера будет 192.168.1.3

вы можете получить доступ к c: /xampp/htdocs/comments.php используя http://192.168.one.three/comments.php в приложении phonegap. Но если компьютер и мобильный телефон в той же сети.

Сама Phonegap создает сервер (localhost) внутри приложения Android (apk).

Примечание: 192..168.one.three === 192.168.1.3

  <script>
            $.ajax({ 
                type : "POST", 
                url : "http://192.168.1.3/comment.php", 
                crossDomain: true,
                beforeSend : function() {$.mobile.loading('show')}, 
                complete : function() {$.mobile.loading('hide')}, 
                data : {email : 'email', comment : 'comment'}, 
                dataType : 'json', 
                success : function(response) { 
                    //console.error(JSON.stringify(response)); 
                    alert('Works!');
                }, 
                error : function() { 
                    //console.error("error"); 
                    alert('Not working!'); 
                } 
            }); 
        </script>
0

Кордова не поддерживает файлы PHP только HTML и Javascript. Поэтому, если вы хотите взять mongodb качестве базы данных по умолчанию, вам нужно использовать REST Service (в javascript), которая указывает на онлайн-api (возможно, php), который обрабатывает запросы данных для вашего mongodb (установленного на онлайн-сервере) и доставляет информацию в вашем приложении.

если вам нравится база данных, интегрированная в ваше приложение, вы можете использовать SQLlite данных SQLlite и посмотреть здесь.

https://github.com/brodysoft/Cordova-SQLitePlugin

Ещё вопросы

Сообщество Overcoder
Наверх
Меню