나는 Framework7로 코르도바 어플을 만들고있다. 내 로컬 호스트에있는 파일에 대해 ajax 호출을 만들고 싶습니다. 웹 브라우저에서 localhost의 ajax URL을 누를 때 원하는 결과를 완벽하게 얻고 있습니다. 그러나 Android Studio 에뮬레이터의 Cordova 앱을 통해 아약스 전화를 걸려고하면 실패합니다.코르도바가 아약스 요청을하지 않음
나는 config.xml
코르도바 파일과 관련이 있다고 생각합니다. 다음은 내 전체 confix.xml 내용입니다 : -
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<feature name="Whitelist">
<param name="android-package" value="org.apache.cordova.whitelist.WhitelistPlugin" />
<param name="onload" value="true" />
</feature>
<name>HelloCordova</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="[email protected]" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<access origin="*" />
<access origin="http://*" />
<access origin="https://*" />
<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-intent href="market:*" />
<preference name="loglevel" value="DEBUG" />
</widget>
내 아약스 스크립트 : -
var ajax_url = "http://10.0.2.2/";
jQuery(document).on('pageInit', function (e) {
jQuery.ajax({
url:ajax_url+'api.php/getMenu',
type:'post',
success:function(response)
{
response = jQuery.parseJSON(response);
response = response.payload;
var html = '<ul>';
jQuery(response).each(function(index,value){
htmlpage_name = value.title.replace(/\s/g, '').toLowerCase();
html+='<li>';
if (!/^(f|ht)tps?:\/\//i.test(value.link)) {
html+='<a href="'+htmlpage_name+'.html" class="item-link"><div class="item-content"> <div class="item-inner"> <div class="item-title">'+value.title+'</div></div></div></a>';
}
else
{
html+='<a href="'+value.link+'.html" class="item-link"><div class="item-content"> <div class="item-inner"> <div class="item-title">'+value.title+'</div></div></div></a>';
}
html+='</li>';
});
html+='<li><a href="barcodescan.html" class="item-link"><div class="item-content"> <div class="item-inner"> <div class="item-title">Barcode Scan</div></div></div></li>';
html+='</ul>';
jQuery(".home-page-menu").html(html); }
}); });
것들 내가 시도 : -
1) confix.xml
파일에 액세스 기원을 추가했습니다.
<access origin="*" />
<access origin="http://*" />
<access origin="https://*" />
2) 아약스 전화를 걸고있는 php 파일에 헤더를 추가했습니다.
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: POST,GET,OPTIONS");
3) index.html
에 Content-Security-Policy
메타 태그를 추가했습니다.
<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 *">
제발 나를 도와주세요.
* 값 (또는 ip 만)을 사용하여 connect-src 섹션을 추가하거나 default-src에 *를 넣으십시오. – jcesarmobile