1

私はphonegapandroidを使用してアプリケーションを開発しています。このコードを実行すると、次のエラーが発生します

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <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.1.1/jquery.mobile-1.1.1.min.css" />
        <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
        <title>Insert title here</title>

        <script>
            (function($) {

                $.fn.getPageData = function() {
                    var finalData = "";

                    $.ajax({
                        url : "Demo url.com",
                        type : "GET",
                        success : function(data) {

                            finalData = '<div id="index" data-role="page" data-url="index" tabindex="0" class="ui-page ui-body-c ui-page-active" style="min-height: 386px;"><div data-role="header" class="ui-header ui-bar-a" role="banner"><h3 class="ui-title" role="heading" aria-level="1">First Page</h3></div></div>';

                        },
                        fail : function() {
                            finalData = '<div id="index" data-role="page" data-url="index" tabindex="0" class="ui-page ui-body-c ui-page-active" style="min-height: 386px;"><div data-role="header" class="ui-header ui-bar-a" role="banner"><h3 class="ui-title" role="heading" aria-level="1">Error Page</h3></div></div>';

                        }
                    });
                    this.append(finalData);

                };

            })(jQuery);
            $(document).ready(function() {

                $('body').getPageData();
                //$(a).appendTo("body");
            });
        </script>

    </head>
    <body>

    </body>
</html>

次のエラーが発生しています。

Origin null is not allowed by Access-Control-Allow-Origin.
4

2 に答える 2

0

「外部ホスト」の下のファイルにhttp://localhost(またはローカルホストのURLが何であれ)追加してみてください。phonegap.plistおそらくサポートファイルディレクトリにあります。

于 2013-03-02T10:29:43.453 に答える
0

Ajax呼び出しを行う場合OPTIONS、クロスオリジンリソース共有が許可されているかどうかを検出するために、最初にサーバーに呼び出しが送信されます。戻ってくるヘッダーがこれを許可しない場合は、次のようなエラーが発生します。

デモURLにローカルホスト(またはサーバー自体)を使用してみてください。

ネットワークタブを調べます。

CORSの詳細については、http: //en.wikipedia.org/wiki/Cross-origin_resource_sharinghttp ://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/を参照して ください。

そして、同一生成元ポリシーについて:http: //en.wikipedia.org/wiki/Same_origin_policy

于 2013-03-02T10:26:37.297 に答える