Passion
Passion

Reputation: 662

Display result from server in IBM Worklight

I have implemented HTTP adapter in IBM Worklight. I want to display the result returned from server. I want to display HTML file. My code is

function getFeeds() {
    var input = {
        method : 'get',
        returnedContentType : 'text',
        path : "marketing/partners.html"
    };
    WL.Logger.debug("sdfsds");
    return WL.Server.invokeHttp(input);


}

I want to receive(display) WL.Server.invokeHttp(input). After receiving it I want to parse the data.

Upvotes: 0

Views: 1743

Answers (2)

Anton
Anton

Reputation: 3166

If you retrieve it as plain text, once you got it back to your application, do something like

$("#container-id").html(response.invocationResponse.text);

This will inject the HTML you've retrieved to an element with id container-id.

Upvotes: 2

cnandreu
cnandreu

Reputation: 5111

Take a look at the Server-side Development Getting Started Modules. Inside the HTTP adapter – Communicating with HTTP back-end systems Module on Slide 15 - 'XSL Transformation Filtering' will show you how to filter data you get back from the backend. Further parsing and showing data has to be done on the client using onSuccess callback for WL.Client.invokeProcedure. There's a module for that too.

Here's an example of getting data and showing to a user:

var invocationData = {
    adapter : 'adapter-name',
    procedure : 'procedure-name',
    parameters : []
};

var options = {};

options.onSuccess = function (response) {
       //response is a JavaScript object
       $("#id").html(response.invocationResponse.text);
}

options.onFailure = function (response) {
       alert('Failed!'); //You probably want something more meaningful here.
}

WL.Client invokeProcedure(invocationData, options);

There are JavaScript libraries you can add to make searching for values inside the JSON response easier, such as: jspath and jquery-jspath. There's also XPath if you're working with XML.

Upvotes: 2

Related Questions