意外的过程调用响应

时间:2014-08-01 10:10:31

标签: ibm-mobilefirst worklight-adapters

我正在使用IBM Worklight v6.2。

我想在单击按钮时调用一个过程,以从sql数据库返回详细信息。

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"); 
}

适配器JS

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

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

我想调用数据库中的所有值但是无法执行此操作

1 个答案:

答案 0 :(得分:0)

请参阅以下几乎相同的问题:How to retrieve images from existing database using sql/http adapter from worklight application

也许这就是你真正要做的事情......
loadFeedsSuccess()更改为:

// 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);
    }
}