2017-04-16 90 views
2

我知道这个问题已被问很多很多次在线。我尝试了所有的东西,跑得很快。科尔多瓦白名单插件

我试图将数据发布到服务器并取回一个简单的响应。 很明显,我需要安装cordova白名单插件来实现从应用程序访问外部资源,所以我安装了它。

的错误我得到的回复是: 无法加载资源:净:: ERR_NAME_NOT_RESOLVED

项目信息:

  • 这是一个温泉UI应用
  • 科尔多瓦CLI 6.5.0
  • Android版本6.1.2

安装的插件:

Meta标签:

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> 

工具我使用: 的Windows 10, 的Visual Studio 2015年

我做了什么:

  1. 卸载并使用Visua重新安装了白名单插件升 工作室

  2. 卸载该插件,并通过科尔多瓦CLI

    科尔多瓦插件添加科尔多瓦 - 插件白名单

  3. 卸载重新安装,并通过Github上

    插件重新安装
  4. 我甚至更新科尔多瓦从6.2.0到6.5.0

  5. 我创建了一个简单的e GET请求,看看它是否工作,仍然没有任何工作。

  6. 清除了Visual Studio中的科尔多瓦缓存。

Javascript代码我使用:

$http({ 
    method: 'GET', url: "http://mywebsite.com/simple_get.php" 
}).then(
    function (response) { 
     alert(JSON.stringify(response)); 
    }, 
    function (response) { 
     alert(JSON.stringify(response)); 
    } 
); 

jQuery代码也试过:

var settings = { 
    "async": true, 
    "crossDomain": true, 
    "url": "http://mywebsite.com/demo.php", 
    "method": "GET", 
    "headers": { 
     "content-type": "application/x-www-form-urlencoded", 
     "cache-control": "no-cache" 
    }, 
    "data": {} 
} 

jQuery.ajax(settings).done(function (response) { 
    console.log(response); 
}); 

我不知道怎么了调试,并获得了问题,任何帮助将不胜感激...这是我的应用程序完成的最后一步:(

感谢

回答

0

编辑2:

尝试以上Ajax功能随时随地此代码。

$(document).ajaxError(function(e, jqxhr, settings, exception) { 
    if (jqxhr.readyState == 0 || jqxhr.status == 0) { 
     return; 
    } 
}); 

这将捕获状态0错误并允许jQuery忽略它并继续处理Ajax请求。

仅用于调试目的。

编辑

尝试以下。

$.ajax({ 
    url: 'YourRestEndPoint', 
    headers: {'yourHeaderKey': 'yourHeaderValue', 
'yourHeaderKey2': 'yourHeaderValue2'}, 
    method: 'POST', 
    data: {}, 
    success: function(data){ 
     console.log('succes: '+data); 
    }, 
    error: function (jqXHR, textStatus, errorThrown){ 

     console.log(jqXHR + " " + textStatus + " " + errorThrown); 

     console.log(jqXHR.status); 

    } 
}); 

这应该记录错误好一点。

我从您的问题中看到您正在尝试将数据发布到服务器,但是在您使用GET请求的代码中。端点是否同时接受POST和GET或仅POST。

原始 如果你有一个'姓名未解决'错误,你确保网址是正确的吗?你是否在你有控制权的服务器上运行端点?它是由您还是第三方托管?您的DNS查询有问题吗?如果您尝试使用已知的工作端点,那么相同的代码是否正确工作

可能是由很多因素或各种因素造成的。

白名单插件应自动安装在最新版本的Cordova上。

+0

的URL是正确的,我想击中邮递员的URL,且有响应。 我完全控制了端点服务器,DNS查找没问题。 端点在Ripple Emulator内部正常运行。 我该如何调试? – Rizo

+0

查看我的编辑更好的错误记录。也可以使用jQuery为您的Ajax请求尝试我的格式。 –

+0

它接受POST和GET,我尝试了你发给我的JS。 jqHXR的输出为: '[object Object] controllers。JS(111,25) { [功能]:, __proto__:{}, readyState的:0, 状态:0, 状态文本:错误 }' – Rizo

0

这是我config.xml中

<?xml version="1.0" encoding="utf-8"?> 
<widget id="au.com.myapp" version="1.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:vs="http://schemas.microsoft.com/appx/2014/htmlapps"> 
    <name> MyApp</name> 
    <description>fancy user interfaces for hybrid mobile applications. It uses uses Apache Cordova to help you build an app that targets multiple mobile platforms: Android, iOS, Windows, and Windows Phone.</description> 
    <author email="[email protected]" href="http://myappdomain.com">Author</author> 
    <content src="index.html" /> 
    <access origin="*" /> 
    <allow-intent href="*" /> 
    <allow-intent href="http://*/*" /> 
    <allow-intent href="https://*/*" /> 
    <allow-intent href="tel:*" /> 
    <allow-intent href="sms:*" /> 
    <allow-intent href="mailto:*" /> 
    <allow-intent href="geo:*" /> 
    <allow-navigation href="*" /> 
    <allow-intent href="itms:*" /> 
    <allow-intent href="itms-apps:*" /> 
    <vs:features /> 
    <preference name="windows-target-version" value="8.1" /> 
    <preference name="windows-phone-target-version" value="8.1" /> 
    <preference name="DisallowOverscroll" value="true" /> 
    <preference name="Orientation" value="portrait" /> 
    <preference name="loglevel" value="DEBUG" /> 
    <preference name="AndroidLaunchMode" value="singleTop" /> 
    <preference name="ErrorUrl" value="" /> 
    <preference name="Fullscreen" value="True" /> 
    <preference name="KeepRunning" value="true" /> 
    <preference name="SplashScreen" value="screen" /> 
    <preference name="AutoHideSplashScreen" value="false" /> 
    <preference name="SplashScreenDelay" value="20000" /> 
    <preference name="FadeSplashScreen" value="false" /> 
    <preference name="FadeSplashScreenDuration" value=".25" /> 
    <preference name="ShowSplashScreenSpinner" value="false" /> 
    <preference name="AllowInlineMediaPlayback" value="false" /> 
    <preference name="BackupWebStorage" value="cloud" /> 
    <preference name="EnableViewportScale" value="false" /> 
    <preference name="KeyboardDisplayRequiresUserAction" value="true" /> 
    <preference name="MediaPlaybackRequiresUserAction" value="false" /> 
    <preference name="SuppressesIncrementalRendering" value="false" /> 
    <preference name="TopActivityIndicator" value="gray" /> 
    <preference name="GapBetweenPages" value="0" /> 
    <preference name="PageLength" value="0" /> 
    <preference name="PaginationBreakingMode" value="page" /> 
    <preference name="PaginationMode" value="unpaginated" /> 
    <feature name="LocalStorage"> 
    <param name="ios-package" value="CDVLocalStorage" /> 
    </feature> 
    <preference name="UIWebViewDecelerationSpeed" value="normal" /> 
    <preference name="monaca:AndroidIsPackageNameSeparate" value="false" /> 
    <preference name="monaca:targetFamilyiPhone" value="1" /> 
    <preference name="monaca:targetFamilyiPad" value="1" /> 
    <platform name="android"> 
    <icon density="ldpi" src="resources/android/icon/drawable-ldpi/icon.png" /> 
    <icon density="mdpi" src="resources/android/icon/drawable-mdpi/icon.png" /> 
    <icon density="hdpi" src="resources/android/icon/drawable-hdpi/icon.png" /> 
    <icon density="xhdpi" src="resources/android/icon/drawable-xhdpi/icon.png" /> 
    </platform> 
    <platform name="android"> 
    <splash density="land-hdpi" src="resources/android/drawable-land-hdpi/screen.png" /> 
    <splash density="land-ldpi" src="resources/android/drawable-land-ldpi/screen.png" /> 
    <splash density="land-mdpi" src="resources/android/drawable-land-mdpi/screen.png" /> 
    <splash density="land-xhdpi" src="resources/android/drawable-land-xhdpi/screen.png" /> 
    <splash density="port-hdpi" src="resources/android/drawable-port-hdpi/screen.png" /> 
    <splash density="port-ldpi" src="resources/android/drawable-port-ldpi/screen.png" /> 
    <splash density="port-mdpi" src="resources/android/drawable-port-mdpi/screen.png" /> 
    <splash density="port-xhdpi" src="resources/android/drawable-port-xhdpi/screen.png" /> 
    </platform> 
    <platform name="ios"> 
    <splash height="480" src="res/screen/ios/Default~iphone.png" width="320" /> 
    <splash height="960" src="res/screen/ios/[email protected]~iphone.png" width="640" /> 
    <splash height="1024" src="res/screen/ios/Default-Portrait~ipad.png" width="768" /> 
    <splash height="2048" src="res/screen/ios/[email protected]~ipad.png" width="1536" /> 
    <splash height="768" src="res/screen/ios/Default-Landscape~ipad.png" width="1024" /> 
    <splash height="1536" src="res/screen/ios/[email protected]~ipad.png" width="2048" /> 
    <splash height="1136" src="res/screen/ios/[email protected]~iphone.png" width="640" /> 
    <splash height="1334" src="res/screen/ios/Default-667h.png" width="750" /> 
    <splash height="2208" src="res/screen/ios/Default-736h.png" width="1242" /> 
    <splash height="1242" src="res/screen/ios/Default-Landscape-736h.png" width="2208" /> 
    <splash src="res/screen/ios/[email protected]~universal~anyany.png" /> 
    <splash src="res/screen/ios/[email protected]~universal~comany.png" /> 
    <splash src="res/screen/ios/[email protected]~universal~comcom.png" /> 
    <splash src="res/screen/ios/[email protected]~universal~anyany.png" /> 
    <splash src="res/screen/ios/[email protected]~universal~anycom.png" /> 
    <splash src="res/screen/ios/[email protected]~universal~comany.png" /> 
    </platform> 
    <plugin name="cordova-plugin-camera" spec="~2.4.0" /> 
    <plugin name="cordova-plugin-compat" version="1.1.0" /> 
    <plugin name="cordova-plugin-file" spec="~4.3.2" /> 
    <plugin name="cordova-plugin-inappbrowser" version="1.7.0" /> 
    <plugin name="cordova-plugin-splashscreen" version="4.0.2" /> 
    <plugin name="cordova-plugin-whitelist" version="1.3.2" /> 
</widget> 
+0

这看起来很好。 应该允许您访问应用程序之外的任何URL。 –

+0

我试过所有的东西..我从头开始创建一个空白的应用程序,只是添加了一个简单的GET白名单插件,这也不起作用。它可以是PC配置吗? – Rizo

+0

你好吗?在设备或模拟器上?你可以用铬进行测试并检查控制台吗? –