Javascript Phonegap AJAX URL显示android设备上的状态404

Javascript Phonegap AJAX URL显示android设备上的状态404,javascript,android,jquery,cordova,phonegap-plugins,Javascript,Android,Jquery,Cordova,Phonegap Plugins,我是新来的Phonegap/Cordova。我在移动设备上遇到了两天无法调用AJAX(URL)的问题。我尝试了每一件事,阅读了每一个论坛,但没有任何效果。在手机上,它总是向我显示“状态404”。它在Ripple仿真器上运行良好。甚至我在许多论坛上阅读时也使用promise.js。下面是代码片段: var app = { initialize: function() { this.bindEvents(); }, // Bind Event Listeners // // Bind an

我是新来的
Phonegap/Cordova
。我在移动设备上遇到了两天无法调用
AJAX
(URL)的问题。我尝试了每一件事,阅读了每一个论坛,但没有任何效果。在手机上,它总是向我显示“
状态404
”。它在Ripple仿真器上运行良好。甚至我在许多论坛上阅读时也使用promise.js。下面是代码片段:

 var app = {
initialize: function() {
    this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {

    $(document).ready(function () {
        var pageData;

        $('#test-form').submit(function(event) {
            event.preventDefault();
            var formVal1 = $('#formVal1').val().trim();
            var formVal2 = $('#formVal2').val().trim();

            if (formVal1 != '' && formVal2 != '')    {
                // B-> Here you define its functions and its payload
                var mdnAPI = 'https://developer.mozilla.org/en-US/search.json';
                /*var payload = {
                    'formVal1' : formVal1,
                    'formVal2' : formVal2
                };*/
                var payload = {
                    'topic' : 'js',
                    'q'     : 'Promise'
                }

                var callback = {
                    success : function(data) {
                    console.log(1, 'success', JSON.parse(data));
                    /* $.mobile.changePage("#application-status", {
                        respData: JSON.parse(data),
                        transition: "flip"
                     }); */
                  },
                  error : function(data) {
                     console.log(2, 'error', JSON.parse(data));
                  }
                };

                $.support.cors=true;
                // Executes the method call
                $http(mdnAPI)
                    .post(payload)
                    .then(callback.success)
                    .catch(callback.error);
            }
            return false;       //this is must
        });
    }
  }
AndroidManifest.xml

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.project.sample.buildingpermit" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
        <intent-filter android:label="@string/launcher_name">
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="22" />
  <access origin="*" />
  <access origin="https://developer.mozilla.org/en-US/search.json" />
    <script src="cordova.js"></script>
    <script src="js/index.js"></script>
    <script>
        $(document).bind( "mobileinit", function() {
        // Make your jQuery Mobile framework configuration changes here!
        alert('I am here ');
        $.mobile.allowCrossDomainPages = true;
        });
    </script>
    <script type="text/javascript">
        $.support.cors=true;
        app.initialize();
    </script>
index.html

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.project.sample.buildingpermit" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
        <intent-filter android:label="@string/launcher_name">
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="22" />
  <access origin="*" />
  <access origin="https://developer.mozilla.org/en-US/search.json" />
    <script src="cordova.js"></script>
    <script src="js/index.js"></script>
    <script>
        $(document).bind( "mobileinit", function() {
        // Make your jQuery Mobile framework configuration changes here!
        alert('I am here ');
        $.mobile.allowCrossDomainPages = true;
        });
    </script>
    <script type="text/javascript">
        $.support.cors=true;
        app.initialize();
    </script>

$(document).bind(“mobileinit”,function(){
//在这里更改jQuery移动框架配置!
警惕(“我在这里”);
$.mobile.allowCrossDomainPages=true;
});
$.support.cors=true;
app.initialize();
注意:我执行命令:

1) cordova平台版本android显示:已安装平台:android 4.0.2

2) phonegap-v显示:5.0.0-0.28.1

有谁能为我提供解决这个问题的方法吗?
我也在我的android设备上打开了移动互联网,但没有任何功能。首先,我现在在URL中使用我的本地网络IP,我部署在Internet上,但仍然不能工作。非常感谢您的帮助。

经过2天的艰苦努力,在@QuickFix的帮助下,问题已经解决。QuickFix一直在上面作出响应

修正:

  • 删除“cordova插件白名单”插件

  • 添加“cordova插件遗留白名单”插件


您是否安装并配置了插件cordova插件白名单?(使用cordova 5创建项目时应自动添加)是的,我安装了cordova-plugin-whitelist.com,您是否已完全配置它(在config.xml和html文件中?)检查此链接,插件文档:是的,config.xml附在上面。请检查其是否满足白名单要求。