(最近6个小时一直在这里)我正在尝试制作一个phonegap/Cordova应用程序.我无法通过Android模拟器进行Ajax调用(API ver 22,Android> 4.4).Ajax调用适用于Firefox桌面,但即使在Chrome浏览器上也会失败(与模拟器上的情况相同)
cordova --version 5.0.0
码:
$.ajax({
url: serverUrl,
type: 'GET',
contentType: "application/json",
async: true,
dataType: 'jsonp',
callback: 'callback',
jsonpCallback: 'yourcallback',
crossDomain: true,
success: function (result) {
$("#message").html("location sent");
},
error: function (request, error) {
alert('Error ' + error);
}
});
Run Code Online (Sandbox Code Playgroud)
我看到的错误是:
在chrome远程调试器上:
拒绝连接到' http: //10:20.2.2/test/ getLocation.php ',因为它违反了以下内容安全策略指令:"default-src'self'data:gap:https://ssl.gstatic.com '不安全-EVAL'".请注意,'connect-src'未显式设置,因此'default-src'用作后备.
我在博客和帖子上看到了各种设置,但没有用.把一些在这里删除通常的嫌疑人.
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
Run Code Online (Sandbox Code Playgroud)
AppManifest可以访问Internet:
<uses-permission android:name="android.permission.INTERNET" />
Run Code Online (Sandbox Code Playgroud)
config.xml文件:
<access origin="*" /> (have tried all variation, with putting actual server name here like …Run Code Online (Sandbox Code Playgroud) android google-chrome jquery-mobile phonegap-plugins cordova