2014-11-06 42 views
0

我有一個phonegapp應用程序,連接到託管在heroku上的API。我使用Codio和Canary作爲我的模擬器。當我加載谷歌瀏覽器開發工具來查看我的應用程序,它連接比我看在網絡選項卡;它給了我這3個錯誤;定義在Phonegap中訪問外部域

(index):98 GET http://pinball-spring.codio.io:35729/livereload.js?snipver=1 net::ERR_CONNECTION_TIMED_OUT 

(index):1 XMLHttpRequest cannot load http://venuetoronto.herokuapp.com/api/v1/neighbourhoods. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://pinball-spring.codio.io:8100' is therefore not allowed access. 

(index):1 XMLHttpRequest cannot load http://venuetoronto.herokuapp.com/api/v1/search/meta. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://pinball-spring.codio.io:8100' is therefore not allowed access. 

我已經通過的PhoneGap /阿帕奇/科爾多瓦文檔看,和它說白名單爲一個域(這是我認爲我正在試圖做的);進入config.xml文件並顯示這個;

<!-- 
    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://127.0.0.1*"/> <!-- allow local pages --> 

<!-- 
    <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. 
--> 

Image of the emulator screen

回答

0

嘗試添加此:

<access origin="http://pinball-spring.codio.io" /> 

<access origin="http://venuetoronto.herokuapp.com" /> 
0

我也是在這種情況下四天左右,直到我終於找到一個解決。 我知道你會一直看到它在不同的地方有編輯您的config.xml文件:

<access origin="*" /> 

但無論出於何種原因,這並沒有爲我工作,直到我以上更改爲:

<access origin=".*" /> 

而且一切都開始正常工作; -ajax能夠訪問外部主機 -links外部網頁也打開 最後,這裏是爲我

<?xml version="1.0" encoding="UTF-8" ?> 
<widget xmlns = "http://www.w3.org/ns/widgets" 
    xmlns:gap = "http://phonegap.com/ns/1.0" 
    id   = "com.sucep.app" 
    versionCode = "10" 
    version  = "1.0.0" > 


<name>App Name</name> 
<description> 
    My description 
</description> 

<author href="http://tormuto.com" email="[email protected]"> 
    Tormuto 
</author> 

<access origin="*" /> 
<access origin=".*" /> 
<icon src="icon.png" /> 

<gap:config-file platform="android" parent="/manifest"> 
    <uses-permission name="android.permission.ACCESS_NETWORK_STATE" /> 
</gap:config-file> 

<gap:config-file platform="android" parent="/manifest"> 
    <uses-permission name="android.permission.INTERNET" /> 
</gap:config-file> 

<gap:plugin name="com.simplec.plugins.network" /> 
<gap:plugin name="org.apache.cordova.inappbrowser" version="0.5.2" /> 
</widget> 
工作過的配置文件