Javascript Ajax调用在android上不起作用,但在ios Cordova上运行良好

Javascript Ajax调用在android上不起作用,但在ios Cordova上运行良好,javascript,android,ajax,cordova,phonegap-plugins,Javascript,Android,Ajax,Cordova,Phonegap Plugins,编辑:场外服务器端很好,因为ajax在IOS上运行良好,允许浏览器=>跨源请求 我正在开发cordova移动应用程序。我为android和ios构建应用程序,但android应用程序无法工作,dnt无法发送ajax请求。当Ios应用程序正常工作时。这是我的config.xml <?xml version='1.0' encoding='utf-8'?> <widget id="com.unitedway" version="1.0.0" xmlns="http://www.w

编辑:场外服务器端很好,因为ajax在IOS上运行良好,允许浏览器=>跨源请求


我正在开发cordova移动应用程序。我为android和ios构建应用程序,但android应用程序无法工作,dnt无法发送ajax请求。当Ios应用程序正常工作时。这是我的config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.unitedway" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
    <name>fw3</name>
    <description>Hello World sample application that responds to the deviceready event.</description>
    <author email="support@phonegap.com" href="http://phonegap.com">PhoneGap Team</author>
    <content src="index.html" />
    <preference name="AndroidPersistentFileLocation" value="Internal" />
    <preference name="AndroidPersistentFileLocation" value="Compatibility" />
    <preference name="iosPersistentFileLocation" value="Documents" />
    <preference name="iosPersistentFileLocation" value="Compatibility" />
    <preference name="permissions" value="none" />
    <preference name="orientation" value="default" />
    <preference name="target-device" value="universal" />
    <preference name="fullscreen" value="true" />
    <preference name="webviewbounce" value="true" />
    <preference name="prerendered-icon" value="true" />
    <preference name="stay-in-webview" value="false" />
    <preference name="ios-statusbarstyle" value="black-opaque" />
    <preference name="detect-data-types" value="true" />
    <preference name="exit-on-suspend" value="false" />
    <preference name="show-splash-screen-spinner" value="true" />
    <preference name="auto-hide-splash-screen" value="true" />
    <preference name="disable-cursor" value="false" />
    <preference name="android-minSdkVersion" value="14" />
    <preference name="WebSecurity" value="disable" />
    <preference name="android-installLocation" value="auto" />
    <gap:plugin name="org.apache.cordova.battery-status" />
    <gap:plugin name="org.apache.cordova.camera" />
    <gap:plugin name="org.apache.cordova.media-capture" />
    <gap:plugin name="org.apache.cordova.console" />
    <gap:plugin name="org.apache.cordova.contacts" />
    <gap:plugin name="org.apache.cordova.device" />
    <gap:plugin name="org.apache.cordova.device-motion" />
    <gap:plugin name="org.apache.cordova.device-orientation" />
    <gap:plugin name="org.apache.cordova.dialogs" />
    <gap:plugin name="org.apache.cordova.file" />
    <gap:plugin name="org.apache.cordova.file-transfer" />
    <gap:plugin name="org.apache.cordova.geolocation" />
    <gap:plugin name="org.apache.cordova.globalization" />
    <gap:plugin name="org.apache.cordova.inappbrowser" />
    <gap:plugin name="org.apache.cordova.media" />
    <gap:plugin name="org.apache.cordova.network-information" />
    <gap:plugin name="org.apache.cordova.splashscreen" />
    <gap:plugin name="org.apache.cordova.vibration" />
    <icon src="icon.png" />
    <icon gap:platform="android" gap:qualifier="ldpi" src="www/res/icon/android/icon-36-ldpi.png" />
    <icon gap:platform="android" gap:qualifier="mdpi" src="www/res/icon/android/icon-48-mdpi.png" />
    <icon gap:platform="android" gap:qualifier="hdpi" src="www/res/icon/android/icon-72-hdpi.png" />
    <icon gap:platform="android" gap:qualifier="xhdpi" src="www/res/icon/android/icon-96-xhdpi.png" />
    <icon gap:platform="blackberry" src="www/res/icon/blackberry/icon-80.png" />
    <icon gap:platform="blackberry" gap:state="hover" src="www/res/icon/blackberry/icon-80.png" />
    <icon gap:platform="ios" height="57" src="www/res/icon/ios/icon-57.png" width="57" />
    <icon gap:platform="ios" height="72" src="www/res/icon/ios/icon-72.png" width="72" />
    <icon gap:platform="ios" height="114" src="www/res/icon/ios/icon-57-2x.png" width="114" />
    <icon gap:platform="ios" height="144" src="www/res/icon/ios/icon-72-2x.png" width="144" />
    <icon gap:platform="webos" src="www/res/icon/webos/icon-64.png" />
    <icon gap:platform="winphone" src="www/res/icon/windows-phone/icon-48.png" />
    <icon gap:platform="winphone" gap:role="background" src="www/res/icon/windows-phone/icon-173-tile.png" />
    <gap:splash gap:platform="android" gap:qualifier="port-ldpi" src="www/res/screen/android/screen-ldpi-portrait.png" />
    <gap:splash gap:platform="android" gap:qualifier="port-mdpi" src="www/res/screen/android/screen-mdpi-portrait.png" />
    <gap:splash gap:platform="android" gap:qualifier="port-hdpi" src="www/res/screen/android/screen-hdpi-portrait.png" />
    <gap:splash gap:platform="android" gap:qualifier="port-xhdpi" src="www/res/screen/android/screen-xhdpi-portrait.png" />
    <gap:splash gap:platform="blackberry" src="www/res/screen/blackberry/screen-225.png" />
    <gap:splash gap:platform="ios" height="480" src="www/res/screen/ios/screen-iphone-portrait.png" width="320" />
    <gap:splash gap:platform="ios" height="960" src="www/res/screen/ios/screen-iphone-portrait-2x.png" width="640" />
    <gap:splash gap:platform="ios" height="1136" src="www/res/screen/ios/screen-iphone-portrait-568h-2x.png" width="640" />
    <gap:splash gap:platform="ios" height="1024" src="www/res/screen/ios/screen-ipad-portrait.png" width="768" />
    <gap:splash gap:platform="ios" height="768" src="www/res/screen/ios/screen-ipad-landscape.png" width="1024" />
    <gap:splash gap:platform="winphone" src="www/res/screen/windows-phone/screen-portrait.jpg" />
    <allow-navigation href="*" />
    <allow-intent href="*" />
    <access origin="*" subdomains="true" />
    <platform name="android">
        <allow-navigation href="*" />
        <allow-intent href="*" />
    </platform>
    <platform name="ios">
        <allow-navigation href="*" />
        <allow-intent href="*" />
    </platform>
    <engine name="android" spec="~4.1.1" />
    <engine name="ios" spec="~4.1.1" />
    <plugin name="io.phasr.cordova.plugin.itunesfilesharing" spec="https://github.com/christianjunk/cordova-plugin-itunesfilesharing" />
    <plugin name="cordova-plugin-file" spec="~4.2.0" />
    <plugin name="cordova-plugin-whitelist" spec="~1.2.2" />
</widget>

fw3
Hello World示例应用程序,用于响应deviceready事件。
电话差距小组
这是我的android AndroidManifest

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.unitedway" 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" />
    <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.DeviceDefault.NoActionBar" 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="14" android:targetSdkVersion="23" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

我的ajax请求代码返回状态404


所以ajax请求在android上失败,但在ios和浏览器上可以正常工作。

从第5版左右开始,cordova需要。然后
(或您选择的任何来源)应该可以工作。

我下载了您的项目,在我新创建的项目中替换了您的项目源代码,并替换了删除按钮单击函数对我的本地url的AJAX url调用,并且我能够成功地进行AJAX调用。事实上,我已经在成功回调中放置了一个警报,我也得到了警报

因此,无论如何,它与编码无关。这可能是Android平台创建的首要问题,也可能是cordova白名单插件安装的问题


在中发布了工作代码库,还包括插件和Android平台,供您参考。一定要利用它们来进一步发展。希望对您有所帮助。

以上代码很好,您是否允许从要启动ajax的服务器启动ajax。有一个概念是跨源资源共享,您必须允许从服务器端获取应用程序到服务器的请求。要了解更多信息,请@Hassan尝试在android平台的config.XML中添加以下内容-@Gandhi我已经阅读了
,应该和它们一样do@AnantaPrasadLoda对查看我的编辑(在顶部)。。允许来自服务器的跨源请求这是来自应用程序,我是说你必须允许服务器端Mr@SamiPlease中的跨源。请检查我的config.xml。我已经安装了白名单插件,也添加了这个。但它仍然不仅在安卓上工作。我没有注意到,因为它在列表中。对我来说,它完成了任务。请求是否到达服务器?就我而言,它们甚至不是由设备发送的。但如果白名单不是解决方案,我不知道会是什么。@HassanALi我很谦卑。很高兴这有帮助。快乐编码。等待赏金:)cheers@Sami谢谢你,萨米。很高兴我能帮助你们。希望我们能很快就其他问题见面。快乐编码