Phonegap应用程序可以在模拟器上运行而不在设备上

时间:2014-07-31 10:04:08

标签: ajax cordova emulation simulator

我在telerik icenium模拟器和浏览器中进行过m testing simple phonegap app for adding comment with remote server. i测试,它可以正常运行。但是,当我尝试在visual studio模拟器中测试并单击按钮时,它会显示“CordovaBrowser_NavigationFailed :: www / index.html?email =fgg@vv.com& comment = Gjjj”。我也在设备上测试过,但没有任何反应。

这是代码。 index.html - 主页

<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;">

    <title>jQuery form post</title>

    <script src="cordova.js"></script>
    <script src="js/index.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="js/post.js"></script>
    <script src="js/jquery.mobile-1.4.3.js"></script>
    <script>
        function onBodyLoad() {
            document.addEventListener("deviceready", onDeviceReady, false);
        }
    </script>

    <style>
        label, b {
            display: block;
        }
    </style>
</head>
<body onload="onBodyLoad()">
    //<a href="http://bgg.comxa.com/new.php">content</a>
    <div id="landmark-1" data-landmark-id="1">
        <form>
            <label for="email">
                <b>Email</b>
                <input type="email" id="email" name="email">
            </label>

            <label for="comment">
                <b>Comment</b>
                <textarea id="comment" name="comment" cols="30" rows="10"></textarea>
            </label>

            <input type="submit" value="Save">
        </form>
    </div>
</body>
</html>

post.js

$(document).bind('deviceready', function () {
    $.support.cors = true;
    $.mobile.allowCrossDomainPages = true;
    $.mobile.pushStateEnabled = false;
    $(function () {
        $('form').submit(function () {
            var landmarkID = $(this).parent().attr('data-landmark-id');
            var postData = $(this).serialize();

            $.ajax({
                type: 'POST',
                data: postData + '&lid=' + landmarkID,
                //change the url for your project
                url: "http://bgg.comxa.com/new.php",
                crossDomain: true,
                success: function (data) {
                    console.log(data);
                    alert('Your comment was successfully added');
                },
                error: function () {
                    console.log(data);
                    alert('There was an error adding your comment');
                }
            });

            return false;
        });
    });
 }); 

2 个答案:

答案 0 :(得分:0)

据我所知,此错误消息并未声明您的index.html文件存在任何问题,但它似乎根本无法访问它。

查看此主题:Navigation in phonegap application fails when I use GET variables

您尝试访问index.html文件的方式可能有所不同。也许你会直接去&#34; index.html&#34;而不是&#34; www / index.html&#34;,正如它在帖子答案中所述。

希望这有帮助!

答案 1 :(得分:0)

经过大量阅读后,我认为问题出在webkit prowsers上。我读过在基于webkit的浏览器中存在ajax请求的问题。我将在真正的手机设备上试用代码,看看......