Phonegap跨域json数据调用停止在phonegap构建中工作 [英] Phonegap cross domain json data calling stopped working in phonegap build

查看:138
本文介绍了Phonegap跨域json数据调用停止在phonegap构建中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

3天前,当我在phonegap构建它工作正常,但昨天,当我创建一个新的构建从ph​​onegap构建器,它停止工作和获取数据。仅适用于phonegap。

Hi 3 days before when I was working on phonegap build it was working fine but yesterday when I created a new build from phonegap builder it stopped working and getting data. For phonegap only.

以下是我的配置代码。

<!-- Customize your app and platform with the preference element. -->
<preference name="orientation"                value="default" />        <!-- all: default means both landscape and portrait are enabled -->
<preference name="target-device"              value="universal" />      <!-- all: possible values handset, tablet, or universal -->
<preference name="fullscreen"                 value="true" />           <!-- all: hides the status bar at the top of the screen -->
<preference name="webviewbounce"              value="true" />           <!-- ios: control whether the screen 'bounces' when scrolled beyond the top -->
<preference name="prerendered-icon"           value="true" />           <!-- ios: if icon is prerendered, iOS will not apply it's gloss to the app's icon on the user's home screen -->
<preference name="stay-in-webview"            value="false" />          <!-- ios: external links should open in the default browser, 'true' would use the webview the app lives in -->
<preference name="ios-statusbarstyle"         value="black-opaque" />   <!-- ios: black-translucent will appear black because the PhoneGap webview doesn't go beneath the status bar -->
<preference name="detect-data-types"          value="true" />           <!-- ios: controls whether data types (such as phone no. and dates) are automatically turned into links by the system -->
<preference name="exit-on-suspend"            value="false" />          <!-- ios: if set to true, app will terminate when home button is pressed -->
<preference name="show-splash-screen-spinner" value="true" />           <!-- ios: if set to false, the spinner won't appear on the splash screen during app loading -->
<preference name="auto-hide-splash-screen"    value="true" />           <!-- ios: if set to false, the splash screen must be hidden using a JavaScript API -->
<preference name="disable-cursor"             value="false" />          <!-- blackberry: prevents a mouse-icon/cursor from being displayed on the app -->
<preference name="android-installLocation"    value="auto" />           <!-- android: app install location. 'auto' will choose. 'internalOnly' is device memory. 'preferExternal' is SDCard. -->
<!--
    Define a specific version of PhoneGap to build into your app.
    <preference name="phonegap-version"       value="3.5.0" />
-->

<!-- Plugins -->

<!-- Core plugins -->
<gap:plugin name="org.apache.cordova.console" />
<gap:plugin name="org.apache.cordova.device" />
<gap:plugin name="org.apache.cordova.geolocation" />
<gap:plugin name="org.apache.cordova.network-information" />
<gap:plugin name="org.apache.cordova.splashscreen" />

<!-- Third party plugins -->
<!-- A list of available plugins are available at https://build.phonegap.com/plugins -->
<!--
    <gap:plugin name="com.phonegap.plugins.barcodescanner" />
-->

<!-- Define app icon for each platform. -->
<icon src="icon.png" />
<icon src="res/icon/android/icon-36-ldpi.png"   gap:platform="android"    gap:qualifier="ldpi" />
<icon src="res/icon/android/icon-48-mdpi.png"   gap:platform="android"    gap:qualifier="mdpi" />
<icon src="res/icon/android/icon-72-hdpi.png"   gap:platform="android"    gap:qualifier="hdpi" />
<icon src="res/icon/android/icon-96-xhdpi.png"  gap:platform="android"    gap:qualifier="xhdpi" />
<icon src="res/icon/blackberry/icon-80.png"     gap:platform="blackberry" />
<icon src="res/icon/blackberry/icon-80.png"     gap:platform="blackberry" gap:state="hover"/>
<icon src="res/icon/ios/icon-57.png"            gap:platform="ios"        width="57" height="57" />
<icon src="res/icon/ios/icon-72.png"            gap:platform="ios"        width="72" height="72" />
<icon src="res/icon/ios/icon-57-2x.png"         gap:platform="ios"        width="114" height="114" />
<icon src="res/icon/ios/icon-72-2x.png"         gap:platform="ios"        width="144" height="144" />
<icon src="res/icon/webos/icon-64.png"          gap:platform="webos" />
<icon src="res/icon/windows-phone/icon-48.png"  gap:platform="winphone" />
<icon src="res/icon/windows-phone/icon-173.png" gap:platform="winphone"   gap:role="background" />

<!-- Define app splash screen for each platform. -->
<gap:splash src="res/screen/android/screen-ldpi-portrait.png"       gap:platform="android" gap:qualifier="port-ldpi" />
<gap:splash src="res/screen/android/screen-mdpi-portrait.png"       gap:platform="android" gap:qualifier="port-mdpi" />
<gap:splash src="res/screen/android/screen-hdpi-portrait.png"       gap:platform="android" gap:qualifier="port-hdpi" />
<gap:splash src="res/screen/android/screen-xhdpi-portrait.png"      gap:platform="android" gap:qualifier="port-xhdpi" />
<gap:splash src="res/screen/blackberry/screen-225.png"              gap:platform="blackberry" />
<gap:splash src="res/screen/ios/screen-iphone-portrait.png"         gap:platform="ios"     width="320" height="480" />
<gap:splash src="res/screen/ios/screen-iphone-portrait-2x.png"      gap:platform="ios"     width="640" height="960" />
<gap:splash src="res/screen/ios/screen-iphone-portrait-568h-2x.png" gap:platform="ios"     width="640" height="1136" />
<gap:splash src="res/screen/ios/screen-ipad-portrait.png"           gap:platform="ios"     width="768" height="1024" />
<gap:splash src="res/screen/ios/screen-ipad-landscape.png"          gap:platform="ios"     width="1024" height="768" />
<gap:splash src="res/screen/windows-phone/screen-portrait.jpg"      gap:platform="winphone" />

<gap:config-file platform="ios" parent="CFBundleShortVersionString">
<string>100</string>
</gap:config-file>

<!--
    Define access to external domains.

    <access />            - a blank access tag denies access to all external resources.
    <access origin="*" /> - a wildcard access tag allows access to all external resource.

    Otherwise, you can specify specific domains:

    <access origin="http://phonegap.com" />                    - allow any secure requests to http://phonegap.com/
    <access origin="http://phonegap.com" subdomains="true" />  - same as above, but including subdomains, such as http://build.phonegap.com/
    <access origin="http://phonegap.com" browserOnly="true" /> - only allows http://phonegap.com to be opened by the child browser.
-->

<access origin="*"/>
<!-- Added the following intents to support the removal of whitelist code from base cordova to a plugin -->
<!-- Whitelist configuration. Refer to https://cordova.apache.org/docs/en/edge/guide_appdev_whitelist_index.md.html -->
<plugin name="cordova-plugin-whitelist" version="1" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
    <allow-intent href="market:*" />
</platform>
<platform name="ios">
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
</platform>

以下是我的jquery代码

and below is mine jquery code

$(document).on("pagecreate","#login",function(){
                $("#loginForm").submit(function(e) {
                    e.preventDefault();
                    var a = $(this).serializeArray();
                    var un = a[0]['value'];
                    var pw = a[1]['value'];
                 $.ajax({
                    type: "get",
                    url: 'http://animap.azurewebsites.net/json/login_json.php',
                    crossDomain: true,
                    dataType: 'json',
                    data: {
                        email: un,
                        pass: pw
                    },
                    success: function(data)
                    {
                        //var a = JSON.parse(data);
                        alert(data[0]);
                        if (data[0] == 'success') {
                            $.mobile.changePage( "#tracker-options", { transition: "slideup", changeHash: true });
                            $("#user").text(un);
                            user = un;").hide();
                            return false;
                        }
                        else {
                            $("#alert").show();
                        }
                    },
                    error: function(xhr, status, error) { 
                        alert('Failed!');
                        alert(xhr.statusText);
  alert(xhr.responseText);
                         }
                    });
                    return false; // avoid to execute the actual submit of the form.
                });
            });

而这同样的代码适用于cordova,我认为有一些问题config

while this same code works fine with cordova, I assume there is some problem with config file but not able to solve it.


推荐答案

@nirmal,


>
https:// github。 com / jessemonroy650 / top-phonegap-mistakes / blob / master / new-to-Phonegap.md

您打了:


  • #6不为您的编译器设置phonegap版本

  • #7不为插件设置version / li>
  • #10不会在config.xml中添加新的白名单和白名单插件参数。

对于#6& #7

For #6 & #7


使用CLI版本,如果您不为您的平台分配版本或在Phonegap Build没有在config.xml中设置phonegap-version,您将获得最新版本。如果你幸运,你的程序只是按预期工作。如果你不幸运,你会得到一系列的级联错误。

With the CLI version, if you do not assign a version for your platform OR in ''Phonegap Build'' if you do not set the phonegap-version in config.xml, YOU WILL GET THE LATEST VERSION. If you are lucky, your program just works as expected. If you are not lucky, you'll get a set of cascasding error.

幸运的是,我们所有人,霍利Schinsky写了一个很好的博客文章解释这一切:

Luckily for all of us, Holly Schinsky has written a nice blog post to explain it all:

Cordova / PhoneGap版本混淆

http://devgirl.org/2014/11/07/cordovaphonegap-version-confusion/

对于#10


这个相对* NEW *要求意味着 - 网站或资源,您必须使用白名单和白名单插件。如果您使用cordova-android@4.0.0或更高版本,此要求将生效;包括cli-5.1.1。

This relatively * NEW * requirement means – to access ANY website or resources on the web, you MUST use the whitelist and the whitelist plugin. This requirement goes into affect if you are using cordova-android@4.0.0 or better; including cli-5.1.1.

要清楚,白名单已经有一段时间,但插件和要求是非常新的。如您所料,添加白名单后,即会停用defacto开放访问功能。或者说另一种方式,定义开放访问功能被计划和排定消除。

To be clear, the "whitelist" has been around for a bit, but the plugin and requirement is very new. As you would expect, when the "whitelist" was added, the defacto open-access feature was deprecated. Or said another way, the defacto open-access feature was planned and scheduled to be eliminated. This change marks a step in removal of the open-access feature.

Phonegap Build论坛:在PGB上升级到cli-5.1.1的注意事项,现在需要白名单

Phonegap Build Forum: Notes for upgrading to cli-5.1.1 on PGB and now required Whitelist



查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆