从PhoneGap应用程序发送Ajax信号不起作用

时间:2018-04-12 17:08:51

标签: android jquery mobile jquery-mobile phonegap

我正在尝试使用PhoneGap技术开发移动应用程序。

通过使用ajax调用,我想向/从服务器发送/接收数据。

我已经阅读了很多关于如何开发移动应用程序的文章,但这对我不起作用。

我开发了应用程序,它作为网络应用程序运行完美。

当我尝试使用Adobe PhoneGap Build将其转换为移动应用程序时,在我的Android手机上安装后,移动应用程序不会触发ajax api调用。

请帮助,这是我的fiorst移动应用程序,我觉得我错过了一些东西,也许是一些特定的权利,配置......

这是我的html / js / jquery / ajax代码:

<!DOCTYPE html>

<html>

    <head>

        <title>Mobile App</title>

        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>

        <meta name="viewport" content="width=device-width, initial-scale=1" />

        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />

        <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

    </head>

    <body>

        <h1>Mobile App V 1.0.0</h1>

        <p>Description for the mobile app.</p>

        <div data-role="page" id="home">

            <div data-role="header" data-theme="b">

                <h1>Mobile App</h1>

            </div>

            <div data-role="main">

                <div id="api_result"></div>

            </div>

            <div data-role="footer" style="text-align:center;"  data-theme="b">
                <p>&copy; Mobile App</p>
            </div>

        </div>

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

    </body>

</html>

和js / jquery / ajax代码:

$(document).ready(
        function () {

            $.ajax(
                    {
                        type: "POST",
                        url: "http://192.168.1.101/phone-gap/apis/apps/digital-menu/digital-menu-api-v-1.0.1/",
                        crossDomain: true,
                        beforeSend: function () {
                            $.mobile.loading('show')
                        },
                        complete: function () {
                            $.mobile.loading('hide')
                        },
                        data: {},
                        dataType: 'json',
                        success: function (response) {
                            //console.error(JSON.stringify(response));
                            //alert('Works!');
                            $("#api_result").html('abc');
                        },
                        error: function () {
                            //console.error("error");
                            //alert('Now working!');
                            $("#api_result").html('def');
                        }
                    }
            );

        }
);

0 个答案:

没有答案