Question

I am using IBM Worklight v6.2.

I want to invoke a procedure on a click of a button to return details from a sql database.

HTML

<div id ="page">
    <h1> Hi Welcome User</h1>
    <input type="submit"  id="user" onclick="loadFeeds()" value="Submit">
    <span id="result"></span>
</div>

JavaScript

 function loadFeeds(){
     var invocationData = {
         adapter:"car1",
         procedure:"getuser",
         parameters:["name","city"]
     };

     WL.Client.invokeProcedure(invocationData,{
         onSuccess :loadFeedsSuccess,
         onFailure :loadFeedsFailure,
     });
}

function loadFeedsSuccess(result) {
    var xyz=result.invocationResult.resultSet[0];
    $("#result").html(xyz.name+" "+xyz.city);
    //$("#result").html(xyz.city);
    //alert(xyz.name);
}

function loadFeedsFailure(result) {
    WL.Logger.debug("failure"); 
}

Adapter JS

var user = WL.Server.createSQLStatement("select name,city from user");

function getuser(){
    return WL.Server.invokeSQLStatement({
        preparedStatement : user,
        parameters : []
    });
}

I want to invoke all the values from the database but am not able to do that

Was it helpful?

Solution

See the following almost-identical question: How to retrieve images from existing database using sql/http adapter from worklight application

Maybe this is what you're actually trying to do...
Change loadFeedsSuccess() to:

// Change the append to look like how you need it to be, in your app.
function loadFeedsSuccess(result) {
    for (i = 0; i < result.invocationResult.resultSet.length; i++) {
        var xyz=result.invocationResult.resultSet[i];
        $("#result").append("name: " + xyz.name + " city: " + xyz.city);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top