我确实有一个 Cordova 3.3 应用程序,但昨天我将 cordova 和我所有的应用程序插件更新到 apache cordova v5.0。
自从我这样做之后,我安装了启动画面插件并毫无问题地构建了我的应用程序,但是当我尝试测试时,我看到所有外部 ajax 请求都返回一个404 错误,包括一个简单的向 google 发出 ajax 请求。
在任何浏览器上一切正常。
我的config.xml:
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="6000" />
<preference name="SplashMaintainAspectRatio" value="true" />
<platform name="android">
<splash src="screen/android/ldpi.9.png" density="ldpi"/>
<splash src="screen/android/mdpi.9.png" density="mdpi"/>
<splash src="screen/android/hdpi.9.png" density="hdpi"/>
<splash src="screen/android/xhdpi.9.png" density="xhdpi"/>
</platform>
<preference name="loglevel" value="DEBUG"/>
<preference name="AndroidLaunchMode" value="singleTop"/>
<preference name="ErrorUrl" value=""/>
<preference name="monaca:DisableCookie" value="false"/>
<feature name="App">
<param name="android-package" value="org.apache.cordova.App"/>
</feature>
<preference name="monaca:androidVersionCode" value="1"/>
<preference name="KeyboardShrinksView" value="true"/>
<preference name="monaca:MonacaBackendUrl" value="https://cloud.monaca.mobi/json-rpc/"/>
<preference name="monaca:MonacaBackendId" value="5462a7b9fd1734575d0f0317"/>
<preference name="monaca:MonacaBackendApiKey" value="e839514dc867719689001fa1c32a17136adeb1ba631c5885b2f996b1375f9cb4"/>
<preference name="KeepRunning" value="true"/>
<preference name="monaca:AndroidIsPackageNameSeparate" value="false"/>
<preference name="DisallowOverscroll" value="true"/>
<preference name="monaca:WebViewEngine" value="default"/>
<preference name="Orientation" value="portrait"/>
<preference name="Fullscreen" value="false"/>
<preference name="BackgroundColor" value="0xff1b3c81"/>
<access origin="*"/>
我的AndroidManifest.xml
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" android:windowSoftInputMode="adjustPan" package="com.nowa" 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" />
<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:launchMode="singleTop" android:name="Nowa" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.VIBRATE" />
</manifest>
一个 ajax 请求不起作用的例子:
$.ajax( "http://www.google.com.br" )
.done(function() {
alert( "success" );
})
.fail(function() {
alert( "error" );
})
.always(function() {
alert( "complete" );
});
最佳答案
Cordova 5.0 默认阻止外部 http 请求。
尝试添加 cordova-plugin-whitelist到您的项目。
关于android - Cordova/Phonegap 所有外部 Ajax 请求返回 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30014539/