简体   繁体   English

Android Phonegap 3 Webapp白名单不起作用

[英]Android Phonegap 3 webapp whitelist not working

I have a phonegap android application which is attempting to get data from an external server: 我有一个phonegap android应用程序,它正在尝试从外部服务器获取数据:

The server is a .net WebAPI - and uses the communcation is via JSONP. 该服务器是.net WebAPI-并通过JSONP使用通信。 The same code/server works in iOS with phonegap 2.7. 相同的代码/服务器在带phonegap 2.7的iOS中工作。 For Android I am using phonegap 3.1. 对于Android,我正在使用phonegap 3.1。 I have double checked the URL to make sure it's correct. 我已经仔细检查了网址,以确保其正确无误。 I have also got the following line in my config.xml file. 我的config.xml文件中也包含以下行。

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

The request details are here: 请求的详细信息在这里:

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

and the javascript request code is 并且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');
            }
        });

I'm really stuck on this - so i'd really like some help. 我真的很坚持这一点-所以我真的想要一些帮助。 thanks :) 谢谢 :)

I am in the same page as you. 我和你在同一个页面。 It works perfectly on iOS7 and even Android 2.3 virtual machine but it does not work on Android 4.0.3 I am using Phonegap 3.1 它在iOS7甚至Android 2.3虚拟机上都能完美运行,但在Android 4.0.3上却无法运行,我正在使用Phonegap 3.1

--- EDIT --- -编辑-

I have various sites for whitelisting and I put them all in different ways 我有多个网站列入白名单,并且将它们全部以不同的方式放置

<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"/>

Since I am using AngularJS I do not know how to help you in your code, but once I tested using jquery and I did not have your support CORS code. 由于我使用的是AngularJS,因此我不知道如何在您的代码中为您提供帮助,但是,一旦我使用jquery进行了测试,就没有支持您的CORS代码。 I also added the 我还添加了

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

on the config.xml located on res/xml/config.xml. 在位于res / xml / config.xml的config.xml上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM