簡體   English   中英

Android Phonegap 3 Webapp白名單不起作用

[英]Android Phonegap 3 webapp whitelist not working

我有一個phonegap android應用程序,它正在嘗試從外部服務器獲取數據:

該服務器是.net WebAPI-並通過JSONP使用通信。 相同的代碼/服務器在帶phonegap 2.7的iOS中工作。 對於Android,我正在使用phonegap 3.1。 我已經仔細檢查了網址,以確保其正確無誤。 我的config.xml文件中也包含以下行。

<access origin="*" subdomains="true" />

請求的詳細信息在這里:

Request URL:http://XXXXXXXXXXXX.com/server/api/messagetypeopt/1?callback=jQuery17209047717128414661_1386902222072&_=1386902252817
Request Method:GET
Status Code:404 Not Found (from cache)
Request Headersview source
Accept:*/*
User-Agent:Mozilla/5.0 (Linux; Android 4.4; sdk Build/KRT16L) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36
Query String Parametersview sourceview URL encoded
callback:jQuery17209047717128414661_1386902222072
_:1386902252817

並且javascript請求代碼是

$.support.cors = true;
        $.mobile.allowCrossDomainPages = true;
        $.mobile.loading('show');

        // enableFrontPageButtons(1)
        enableButtons(0);
        console.log('about to get message types');
        try {
        $.ajax({
            //url: 'http://localhost:8956/api/messagetypeopt/' + SENDER_ID ,
            url: SERVER + '/api/messagetypeopt/' + SENDER_ID ,
            type: 'GET',
            dataType: 'jsonp',
            jsonp: 'callback',
            crossDomain: true,
            async:   false,
            success: function (data) {
                //alert('1');
                localStorage.setItem("rawMessageTypes", JSON.stringify(data.branches));
                Sender.updateBranchesData(data);
                Sender.updateSenderData(data);
                //alert('2');
                setupBranches(data.branches);
                setMessageTypesDB(data.branches); // store in local database.
                updateMessageTypes(data.branches);
                WriteMessageList( getMessageDataForBranch(JSON.parse(localStorage.getItem("rawMessageTypes"))));
                //alert('3');
                // save sender data and branch data
                enableButtons(1);
                //$('#libName').val(ConfigData.SENDER_NAME);
                changeTheBranch(CURRENT_BRANCH);
               // alert('4');
                //alert('Update Complete');
                $('messagetypepopuptext').text('Update Complete');
                $('messagetypepopup').popup();

            },
            statusCode: {
                500: function() {
                    alert("An incorrect request went to the server, check your UserID? ");
                    enableButtons(1);
                    $.mobile.changePage('#pageSetup', {changeHash: false});
                } ,
                400: function() {
                    alert("An incorrect request went to the server, check your UserID? ");
                    enableButtons(1);
                    $.mobile.changePage('#pageSetup', {changeHash: false});
                }
            },
            error: function (x, y, z) {
                //alert('There was an error getting data from the server');
                enableButtons(0);
                $.mobile.changePage('#pageSetup', {changeHash: false});
            },
            complete: function (a, b) {
                //alert('complete:' + a + '\n' + b);
               $.mobile.loading('hide');
            }
        });

我真的很堅持這一點-所以我真的想要一些幫助。 謝謝 :)

我和你在同一個頁面。 它在iOS7甚至Android 2.3虛擬機上都能完美運行,但在Android 4.0.3上卻無法運行,我正在使用Phonegap 3.1

-編輯-

我有多個網站列入白名單,並且將它們全部以不同的方式放置

<access origin="*://site.com" subdomains="true"/>
<access origin="*://site.com/*" subdomains="true"/>
<access origin="*://site.com/something/*" subdomains="true"/>
<access origin="https://site.com/" subdomains="true"/>

由於我使用的是AngularJS,因此我不知道如何在您的代碼中為您提供幫助,但是,一旦我使用jquery進行了測試,就沒有支持您的CORS代碼。 我還添加了

<access origin="..." subdomains="true"/>

在位於res / xml / config.xml的config.xml上。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM