2012-02-20 3 views
1

나는 phonegap과 편안한 webservice를 처음 사용합니다. 내 질문에 내가 어떻게 둘 다 퓨즈 수 있도록 내가 편안한 webservice 함께 동기화 할 응용 프로그램이 있습니다. jsonp로 샘플 서비스를 시도했지만 phonegap이 서비스를로드하지 않았거나 뭔가 빠졌습니다. 고맙습니다.편안한 웹 서비스가있는 전화 갭

답변

3

당신이 웹 서비스를 호출하고 그 결과

<html> 
<head> 
<script src="js/jquery-1.4.2.js" type="text/javascript" charset="utf-8"></script> 
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script> 
<script> 
function bodyload(){ 
    alert("We are calling jquery's ajax function and on success callback xml parsing are done"); 
$.ajax({ 
    url:'http://www.edumobile.org/blog/uploads/XML-parsing-data/Data.xml', 
    dataType:'application/xml', 
    timeout:10000, 
    type:'POST', 
    success:function(data) { 
     $("#bookInFo").html(""); 
     $("#bookInFo").append("<hr>"); 
     $(data).find("Book").each(function() { 
       $("#bookInFo").append("<br> Name: " + $(this).find("name").text()); 
       $("#bookInFo").append("<br> Address: " + $(this).find("address").text()); 
       $("#bookInFo").append("<br> Country: " + $(this).find("country").text()); 
       $("#bookInFo").append("<br><hr>"); 
     }); 
    }, 
    error:function(XMLHttpRequest,textStatus, errorThrown) {  
     alert("Error status :"+textStatus); 
     alert("Error type :"+errorThrown); 
     alert("Error message :"+XMLHttpRequest.responseXML); 
     $("#bookInFo").append(XMLHttpRequest.responseXML); 
    } 
    }); 
} 
</script> 
</head> 
<body onload="bodyload()"> 
<button onclick="bodyload()">Ajax call</button> 
<p id="bookInFo"></p> 
</body> 
</html> 
+0

감사합니다. 난 이미 그런 짓을했는데 문제는 내가 안드로이드 에뮬레이터에서 phonegap을 실행할 때 데이터가 가져 오지 않는다는 것입니다. (작동하지만 경고 이벤트가 발생하지 않는다는 경고를 포함 시켰습니다.) – jongbanaag

+0

You 이것은 빠뜨릴 수 있습니다 http://stackoverflow.com/a/9359170/28557 –

+0

나는 이미 놀랍게도 그것이 작동하지 않는 것을 이미 알아 냈습니다. 로컬에서 작업하는 데 문제가 있습니까? 왜냐하면 나는 여전히 에뮬레이터와 나머지 서비스를 로컬에서 실행하기 때문입니다. – jongbanaag

1

그것은 (JSON 사용) 일반 웹 프로젝트와 동일하게 작동 표시를 구문 분석하는 방법을 이해 아래 코드 도움말 :

$.ajax({ 
url: 'http://...', 
type: 'POST', 
dataType: 'json', 
data: data, 
success: : function(data) { 
//... 
}, 
error: function(xhr, textStatus, errorThrown) { 
//... 
}, 
beforeSend: function (xhr) { 
xhr.setRequestHeader('Content-Type', 'application/json'); 
xhr.setRequestHeader('Accept', 'application/json'); 
} 
}); 

유일한 차이점은 PhoneGap에서 동일한 발신 정책 문제에 대해 걱정할 필요가 없다는 것입니다. 따라서 JSONP의 사용은 실제로 필요하지 않습니다. JSONP 만 처리하고 JSON은 처리하지 않는 서버로 작업하는 경우가 아니면

1

아약스 호출이 약간 변경되었습니다. 요청을 게시해야합니다. 또한 jquery.js가 제일 먼저 나와야합니다. 장치 준비 기능도 호출하십시오.

$.ajax({ 
    url:'http://www.edumobile.org/blog/uploads/XML-parsing-data/Data.xml', 
    dataType:'xml', 
    type:'get', 
    cache: false, 
관련 문제