2013-08-03 21 views
0

對於worklight是新的,在我的應用程序中通過工作燈適配器獲得JSON響應。在仿真器中,只有在調用work-light過程後,響應才能正確顯示。 但是,當我運行它在真正的設備響應不display.Can任何人知道幫助我解決這個問題。在ibm Worklight中獲取json響應,值不會在實際設備中顯示

MY適配器的XML代碼:

<?xml version="1.0" encoding="UTF-8"?> 
<!-- 
Licensed Materials - Property of IBM 
5725-G92 (C) Copyright IBM Corp. 2011, 2013. All Rights Reserved. 
US Government Users Restricted Rights - Use, duplication or 
disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
--> 
<wl:adapter name="JSON" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:wl="http://www.worklight.com/integration" 
xmlns:http="http://www.worklight.com/integration/http"> 

<displayName>JSON</displayName> 
<description>JSON</description> 
<connectivity> 
    <connectionPolicy xsi:type="http:HTTPConnectionPolicyType"> 
     <protocol>http</protocol> 
     <domain>www.name.in</domain> 
     <port>80</port>   
    </connectionPolicy> 
    <loadConstraints maxConcurrentConnectionsPerNode="2" /> 
</connectivity> 


<procedure name="getJSONs"> </procedure> 
<procedure name="addJSON"> </procedure> 
<procedure name="updateJSON"> </procedure> 
<procedure name="deleteJSON"> </procedure> 

MY適配器JS代碼:

function getJSONs() { 

var input = { 
    method : 'get', 
    returnedContentType : 'json', 
    path : 'getMerchantdetails?json=', 

}; 

return WL.Server.invokeHttp(input); 
} 

MY MAIN JS CODE

function wlCommonInit(){ 

busyIndicator = new WL.BusyIndicator("view0"); 

// Common initialization code goes here 
$("#btn").click(function(){ 
getJSONs(); 
}); 
} 

function getJSONs(){ 
//busyIndicator.show(); 
    var invocationData = 
    { 
    adapter : "JSON", 
    procedure : "getJSONs", 
    parameters : [] 
    }; 

    WL.Client.invokeProcedure(invocationData, 
      { 
     onSuccess : merchantdetails, 
     //onFailure : mobGmapLatLngFailure, 

      }); 

    function merchantdetails(result) { 
     var httpStatusCode = result.status; 
     //var div = $("#invokeResult"); 
     if (200 == httpStatusCode) { 
      var invocationResult = result.invocationResult; 
      var isSuccessful = invocationResult.isSuccessful; 
      if (true == isSuccessful) { 
       var result = invocationResult.merchant_detail; 

       //alert(result[0].merchant_long_desc+" - "+result[0].merchant_contact_number); 
       $("#txt").html(result[0].merchant_long_desc+" - "+result[0].merchant_contact_number); 

      } else { 
       //div.append("Request Failed!"); 
      } 
     } else { 
      //div.append("Request Failed!"); 
     } 
    } 
} 

您正在使用哪個工作燈的版本MY SONĴ響應

"merchant_detail": [ 
    { 
    "merchant_code": "1", 
    "merchant_contact_number": "2147483647", 
    "merchant_logo": "", 
    "merchant_long_desc": "Anjappar", 
    "merchant_short_desc": "Anjappar", 
    "merchant_type_code": "1" 
    } 
], 

回答

2

?如果您使用的是6.0以前版本的worklight,則應該檢查applicationDescriptor文件以確保您沒有將「localhost」硬編碼爲您設備連接的服務器。您的模擬器可以連接到本地主機,因爲它與您的worklight服務器在同一臺機器上運行,但您的設備需要一個實際的IP地址。

此外請務必仔細檢查設備上的互聯網連接。

+0

上午使用工作燈6.0。和雅我的設備有互聯網連接,如何設置IP地址。 – Yugesh

+1

嘗試從設備調用適配器時獲得的錯誤消息是什麼?是否有可能阻止設備與Worklight服務器進行通信?像防火牆? – jnortey

+0

如何從device.i調用適配器,但沒有從device.am調用適配器,只是在設備中運行apk文件。 – Yugesh

相關問題