简体   繁体   中英

Unable to invoke adapter procedure

I'm using IBM MobileFirst to create an app. I've created an HTTP Adapter and now I'm working on the invocation of the response within my main.js file. Here is the invokeProcedure call (the invocationData var calls the adapter and the procedure within that adapter):

    WL.Client.invokeProcedure(invocationData,{
       onSuccess : loadSuccess(),
       onFailure : loadFailure(),
    });

Now, I've defined a loadSuccess() and a loadFailure() function (declared before the invocation) as such (simple for testing purposes):

    var loadSuccess = function(result){
       alert("success");
       alert(result.invocationResult);
    }

    var loadFailure = function(result){
       alert("failure");
       alert(result.invocationResult);
    }

However, while "success" and "failure" will flash, "result" is coming back as null. Every tutorial I have seen as used these methods with success, so I am confused as to why my similar implementation is not working. Furthermore, the invokeProcedure function seems to be calling and flashing the results of both the success and failure options!

My adapter returns an appropriate response when I just test that, so why isn't the invocation of the data working correctly? IBM documentation is not very clear, so I appreciate any and all suggestions!

EDIT:

I updated main.js to the following code:

    function loadSuccess(result){
      alert("success");
    }

    function loadFailure(result) {
      alert("failure");
    }

 function testFunc(userid, password) {
     var invocationData = {
        adapter : 'myAdapter',
        procedure : 'myProc',
        parameters : [ userid, password ],
    };

    WL.Client.invokeProcedure(invocationData,{
       onSuccess : loadSuccess,
       onFailure : loadFailure
   });
}

When I test my adapter, by simply calling it, the response is successful and contains all the response information I want. So why isn't onSuccess being called here?

Likely you need to remove the param brackets from the onSuccess and onFailure declarations, otherwise it runs the functions when assigned rather than when needed:

WL.Client.invokeProcedure(invocationData,{
   onSuccess : loadSuccess,
   onFailure : loadFailure
});

Since you're using "var" to define your onSuccess/onFailure callbacks make sure they're in the same scope. Try providing inline callbacks, eg

WL.Client.invokeProcedure(invocationOptions, {
   onSuccess: function(data){ alert....},
   onFailure: function(data){ alert....}
})

You have to declare initOptions.js , main.js and messages.js in the html file that will use the controller that points to your adapter ..

else the invokeProcedure will be undifined

just go to your html file and but this code in the end of body tag directly before closing tag

<script src="js/initOptions.js"></script>
<script src="js/main.js"></script>
<script src="js/messages.js"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM