웹 서비스에서 JSON 데이터에 액세스하는 HTML5 앱을 만들었습니다. 이 응용 프로그램은 데스크탑 컴퓨터의 브라우저에서 열었을 때 제대로 작동하지만 Android 응용 프로그램에 "전화를 거는"경우 작동하지 않습니다.전화 안 된 Android 애플리케이션이 HTML5 앱과 비교하여 작동하지 않음
header("Access-Control-Allow-Origin: *");
다음은 코드입니다 : 나는 CORS 사용하려면 PHP 서버에 다음 줄을 추가했습니다! "오류가 발생했습니다"
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery.getJSON demo</title>
<style>
img {
height: 100px;
float: left;
}
</style>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div id="images"></div>
<script>
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// XDomainRequest for IE.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
}
function onMyClick() {
console.info(new Object("Hello"));
var url = 'http://example.com/mobile/index.php?tag=getAllById&catid=60';
var xhr = createCORSRequest('GET', url);
if (!xhr) {
throw new Error('CORS not supported');
}
xhr.onload = function() {
var responseText = xhr.responseText;
console.info(responseText);
// process the response.
};
xhr.onerror = function() {
console.info('There was an error!');
};
xhr.send();
console.info(new Object("Hello 4"));
}
</script>
<input type="button" value="OK" onclick="onMyClick()"/>
</body>
</html>
이 안드로이드 응용 프로그램을 작동하지
내가 얻고 있음을 의미를 이클립스의 콘솔에 응답 텍스트로 JSON 데이터 대신 onerror 이벤트가 출력된다. 제발 아무도 안드로이드 응용 프로그램 으로이 작업을 얻을 수 있습니다.
인터넷 연결에 문제가있었습니다. 실제로 저는 2 개의 인터넷 연결을 가지고 있으므로 테스트중인 타블렛이 작동하지 않는 인터넷 연결에 연결되어 있지만 HTML5 응용 프로그램을 테스트하고있는 PC는 인터넷 연결에 연결되어있어서 HTML5 응용 프로그램으로 작동하고있었습니다 그러나 "Phonegapped"안드로이드 응용 프로그램은 아닙니다. –