Ajax调用Cordova ios SecurityError:DOM Exception 18

嗨我通过cordova(5.1.1)/ Phonegap构buildiOS应用程序,我有一个问题,我无法解决。

一个基本的Ajax调用抛出一个SecurityError: DOM Exception 18我尝试了所有关于白名单的技巧,现在我迷路了..任何人都可以帮忙? 谢谢。

设备准备就绪后,我会做这件事情:

  var getUrl = 'http://shopplo.com/api/posts/radius/'+app.lat_min+'x'+app.lat_max+'x'+app.lng_min+'x'+app.lng_max+''; //console.log(getUrl); var getPosts = $.ajax({ method: 'GET', url: getUrl, dataType: 'JSON' }) .done(function(e) { console.log( e ); }) .fail(function(e) { //console.log( "error"); $.each(e, function(key, element) { console.log('key: ' + key + '\n' + 'value: ' + element); }); }) .always(function() { console.log( "complete" ); }); 

getUrl是: http : //shopplo.com/api/posts/radius/37.11032230061141×73.11032230061141x-20.572796183027627×42.36447502674581

我得到:

 2015-07-20 01:12:55.981 ShopploLight[779:568632] key: responseJSON :: value: undefined 2015-07-20 01:12:55.983 ShopploLight[779:568632] key: status :: value: 0 2015-07-20 01:12:55.983 ShopploLight[779:568632] key: statusText :: value: Error: SecurityError: DOM Exception 18 2015-07-20 01:12:55.984 ShopploLight[779:568632] complete 

检查你的元标记。 默认情况下,它使用:

 <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"> 

使用下面的代码来启用所有请求

 <!-- Enable all requests, inline styles, and eval() --> <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src: 'self' 'unsafe-inline' 'unsafe-eval'"> 

由于语法不正确,上述答案错误。

以下是正确的:

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

而不是允许所有的东西,你可以只允许你正在做Ajax调用的url。 例如,如果我想从facebook API获取某些内容,可以使用以下方法:

 <meta http-equiv="Content-Security-Policy" content="style-src 'self' 'unsafe-inline'; script-src: 'self' https://graph.facebook.com">