새로운 기능입니다. http 어댑터, 에서 json 응답을 얻으려고했지만 장치에 표시 할 수 없습니다. javascript 코드에 몇 가지 알림을 추가하고 json 개체의 크기를`undefined`로 반환한다는 것을 알았습니다. Worklight에서 HTTP 어댑터의 응답 받기
여기 내 어댑터입니다 자바 스크립트 파일 :function getGooglePlaces(location,name) {
var input = {
method : 'get',
returnedContentType : 'json',
path : 'maps/api/place/search/json',
headers: {
Host: 'maps.googleapis.com'
},
parameters : {
'key' : MyKey,
'location' : location,
'radius' : '10000',
'sensor' : 'false',
'name' : name
}
};
var response = WL.Server.invokeHttp(input);
return response;
}
function addGooglePlace(param1) {
var input = {
method : 'put',
returnedContentType : 'json',
path : 'userInputRequired'
};
return WL.Server.invokeHttp(input);
}
내 main.js 파일 :
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(loadHTTPRecords);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}
function loadHTTPRecords(position){
var invocationData = {
adapter : 'GooglePlaces',
procedure : 'getGooglePlaces',
parameters : [position.coords.latitude+','+position.coords.longitude,'dead battery']
};
WL.Client.invokeProcedure(invocationData,{
onSuccess : loadHTTPQueerySuccess,
onFailure : loadHTTPQueeryFailure
});
}
function loadHTTPQueerySuccess(result){
WL.Logger.debug("Retrieve success" + JSON.stringify(result));
displayFeeds(result);
}
function loadHTTPQueeryFailure(result){
WL.Logger.error("Retrieve failure");
}
function displayFeeds(items){
alert("In displayFeeds");
// Get the size of an object
var ul = $('#itemsList');
alert("before for loop");
alert(items.size);
for (var i = 0; i < items.size; i++) {
alert("inside for loop 1");
for(var j=0;j<i;j++){
alert("in for loop 2");
var li = $('<li/>').html(items[i].name);
li.append($('<hr>'));
ul.append(li);
}
}
}
내가 뭘 잘못 제안하십시오. 난 당신이 당신은 결과의 길이를 얻기 위해 노력하고있다 items.size을 통해 제대로 질문을 이해하면
내 샘플 JSON 응답
{
"html_attributions": [
],
"isSuccessful": true,
"responseHeaders": {
"Alternate-Protocol": "443:quic",
"Cache-Control": "public, max-age=300",
"Content-Type": "application\/json; charset=UTF-8",
"Date": "Tue, 11 Feb 2014 12:04:13 GMT",
"Expires": "Tue, 11 Feb 2014 12:09:13 GMT",
"Server": "mafe",
"Transfer-Encoding": "chunked",
"Vary": "Accept-Language",
"X-Frame-Options": "SAMEORIGIN",
"X-XSS-Protection": "1; mode=block"
},
"responseTime": 236,
"results": [
{
"geometry": {
"location": {
"lat": 52.057049,
"lng": 1.153298
}
},
"icon": "http:\/\/maps.gstatic.com\/mapfiles\/place_api\/icons\/cafe-71.png",
"id": "ec0955fb06fd95d639c89d12475624627250abac",
"name": "Costa Coffee",
"opening_hours": {
"open_now": true
},
"price_level": 2,
"rating": 3.9,
"reference": "CnRuAAAABmdY6kIxRQZw68hqjZ_wwBE29sdSgYuOkXf2IvZTe77aG-AgoCaahu1c9cddHA0Z1D2EdELAEuDyl38xV1G5YcvP3pOm2p0IwVkuvYIJSA1IKAGLIQym21SpXvhUSqBxrpHKBvgTNnUg69lHROaMyxIQvvP8SeCG_dzKi_JgrdrgRRoUQXqH4UkDtA-58bCbdRzUCdXTRVU",
"types": [
"cafe",
"food",
"establishment"
],
"vicinity": "1-5 Queen St, Ipswich"
},
사용하여 어댑터 절차를 호출하는 동안 응답을받을 수 있나요 ** 호출 작업등 절차 ** –
그래, 내가 프로 시저를 호출 할 때 응답을 가지고 있지만 배열 결과에 액세스하려고하면 문제가 발생한다. 'undefined'가된다. – ravi
json을 잘못된 방향으로 가로 지르고 있다고 생각하기 때문에 질문에 샘플 결과를 제공 할 수 있는가? –