Yugesh
Yugesh

Reputation: 4090

Get json response in ibm Worklight, values not display in real device

Am new to worklight,In my application am get JSON response through work-light adapter.In emulator the response will display correctly only after invoke the work-light procedure. But when i run it in real device response was not display.Can any one know help me to solve this issue.

MY adapter XML code:

<?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 adapter JS code:

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 J SON RESPONSE

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

Upvotes: 0

Views: 1135

Answers (1)

jnortey
jnortey

Reputation: 1625

Which version of worklight are you using? If you're using a pre-6.0 version of worklight, you should check your applicationDescriptor file to make sure that you don't have "localhost" hardcoded as the server that your device connects to. Your emulator can connect to localhost just fine since it runs on the same machine as your worklight server but your device needs an actual IP address.

Also make sure to double check the internet connection on your device.

Upvotes: 2

Related Questions