2017-12-15 12 views
0

私はPhonegap/Cordovaを使用して、wordpressのWP-APIで接続を試しています。私がテストしたphonegap/cordovaとのクロスドメインエラー

<IfModule mod_headers.c> 
    Header set Access-Control-Allow-Origin "*" 
</ IfModule> 

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/server/
RewriteRule^index \ .php $ - [L] 
RewriteCond% {REQUEST_FILENAME}! -f 
RewriteCond% {REQUEST_FILENAME}! -d 
RewriteRule. /server/index.php [L] 
</ IfModule> 

# END WordPress 

「 'アクセス制御 - 許可 - 起源' ヘッダが要求されたリソース上に存在する

私のAJAX:。

jQuery.ajax ({ 
    url: 'linktoserver.com/wp-json/wp/v2/publication?_embed', 
    method: 'GET', 
    crossDomain: true, 
    error: function (xhr, status, error) { 

    }, 
    success: function (result) { 
     renderMap (result) 
    } 
}); 

私の.htaccessシミュレータを使用しているすべてのブラウザでテスト用に自分の携帯電話を使用し、すべての場合にエラーが続きます。

EDIT 1:

私のconfig.xml:

<?xml version='1.0' encoding='utf-8'?> 
<widget id="com.e4g.app" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> 
    <name>MyApp</name> 
    <description> 
     MyApp. 
    </description> 
    <author email="[email protected]" href="[email protected]"> 
     MyApp Team 
    </author> 
    <access origin="*" /> 
    <allow-intent href="*" /> 
    <allow-navigation href="*" /> 
    <preference name="Orientation" value="portrait" /> 
    <preference name="DisallowOverScroll" value="true" /> 
    <preference name="BackgroundColor" value="#1FB5FCFF" /> 
    <icon gap:platform="ios" height="60" src="res/icons/ios/icon-60.png" width="60" /> 
    <icon gap:platform="ios" height="120" src="res/icons/ios/icon-60-2x.png" width="120" /> 
    <icon gap:platform="ios" height="180" src="res/icons/ios/icon-60-3x.png" width="180" /> 
    <icon gap:platform="ios" height="76" src="res/icons/ios/icon-76.png" width="76" /> 
    <icon gap:platform="ios" height="152" src="res/icons/ios/icon-76-2x.png" width="152" /> 
    <icon gap:platform="ios" height="40" src="res/icons/ios/icon-40.png" width="40" /> 
    <icon gap:platform="ios" height="80" src="res/icons/ios/icon-40-2x.png" width="80" /> 
    <icon gap:platform="ios" height="57" src="res/icons/ios/icon-57.png" width="57" /> 
    <icon gap:platform="ios" height="114" src="res/icons/ios/icon-57-2x.png" width="114" /> 
    <icon gap:platform="ios" height="72" src="res/icons/ios/icon-72.png" width="72" /> 
    <icon gap:platform="ios" height="144" src="res/icons/ios/icon-72-2x.png" width="144" /> 
    <icon gap:platform="ios" height="29" src="res/icons/ios/icon-small.png" width="29" /> 
    <icon gap:platform="ios" height="58" src="res/icons/ios/icon-small-2x.png" width="58" /> 
    <icon gap:platform="ios" height="50" src="res/icons/ios/icon-50.png" width="50" /> 
    <icon gap:platform="ios" height="100" src="res/icons/ios/icon-50-2x.png" width="100" /> 
    <icon gap:platform="android" gap:qualifier="ldpi" src="res/icons/android/icon-36-ldpi.png" /> 
    <icon gap:platform="android" gap:qualifier="mdpi" src="res/icons/android/icon-48-mdpi.png" /> 
    <icon gap:platform="android" gap:qualifier="hdpi" src="res/icons/android/icon-72-hdpi.png" /> 
    <icon gap:platform="android" gap:qualifier="xhdpi" src="res/icons/android/icon-96-xhdpi.png" /> 
    <icon gap:platform="android" gap:qualifier="xxhdpi" src="res/icons/android/icon-144-xxhdpi.png" /> 
    <icon gap:platform="android" gap:qualifier="xxxhdpi" src="res/icons/android/icon-192-xxxhdpi.png" /> 
    <splash src="splash.png" /> 
    <splash gap:platform="ios" height="480" src="res/screens/ios/screen-iphone-portrait.png" width="320" /> 
    <splash gap:platform="ios" height="960" src="res/screens/ios/screen-iphone-portrait-2x.png" width="640" /> 
    <splash gap:platform="ios" height="1024" src="res/screens/ios/screen-ipad-portrait.png" width="768" /> 
    <splash gap:platform="ios" height="2048" src="res/screens/ios/screen-ipad-portrait-2x.png" width="1536" /> 
    <splash gap:platform="ios" height="768" src="res/screens/ios/screen-ipad-landscape.png" width="1024" /> 
    <splash gap:platform="ios" height="1536" src="res/screens/ios/screen-ipad-landscape-2x.png" width="2048" /> 
    <splash gap:platform="ios" height="1136" src="res/screens/ios/screen-iphone-568h-2x.png" width="640" /> 
    <splash gap:platform="ios" height="1334" src="res/screens/ios/screen-iphone-portrait-667h.png" width="750" /> 
    <splash gap:platform="ios" height="2208" src="res/screens/ios/screen-iphone-portrait-736h.png" width="1242" /> 
    <splash gap:platform="ios" height="1242" src="res/screens/ios/screen-iphone-landscape-736h.png" width="2208" /> 
    <splash gap:platform="android" gap:qualifier="land-hdpi" src="res/screens/android/screen-hdpi-landscape.png" /> 
    <splash gap:platform="android" gap:qualifier="land-ldpi" src="res/screens/android/screen-ldpi-landscape.png" /> 
    <splash gap:platform="android" gap:qualifier="land-mdpi" src="res/screens/android/screen-mdpi-landscape.png" /> 
    <splash gap:platform="android" gap:qualifier="land-xhdpi" src="res/screens/android/screen-xhdpi-landscape.png" /> 
    <splash gap:platform="android" gap:qualifier="port-hdpi" src="res/screens/android/screen-hdpi-portrait.png" /> 
    <splash gap:platform="android" gap:qualifier="port-ldpi" src="res/screens/android/screen-ldpi-portrait.png" /> 
    <splash gap:platform="android" gap:qualifier="port-mdpi" src="res/screens/android/screen-mdpi-portrait.png" /> 
    <splash gap:platform="android" gap:qualifier="port-xhdpi" src="res/screens/android/screen-xhdpi-portrait.png" /> 
    <engine name="ios" spec="^4.4.0" /> 
    <plugin name="cordova-plugin-camera" spec="^2.4.1"> 
     <variable name="CAMERA_USAGE_DESCRIPTION" value=" " /> 
     <variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value=" " /> 
    </plugin> 
    <plugin name="cordova-plugin-transport-security" spec="^0.1.2" /> 
    <plugin name="cordova-plugin-whitelist" spec="^1.3.2" /> 
</widget> 

答えて

0

あなたはその後、file://として使用され、あなたがものを提供しない場合は、AjaxのURL(http://またはhttps://)にプロトコルを追加する必要がありますCordova/Phonegapアプリはそのプロトコルを使用してwwwフォルダからアプリケーションコードをロードします

+0

http:// – Juliano

+0

で動作しませんでした。これはホワイトリストの設定の問題かもしれません。config.xml – jcesarmobile

+0

私はコードを編集し、 config.xml – Juliano

関連する問題