IBM Worklight - Could not invoke the SQL adapter procedure for the insert query from the client side . What's wrong with my coding?

StackOverflow https://stackoverflow.com/questions/22317879

Question

I'm getting a blank screen while running the code in the webpage. The adapter procedure alone is getting invoked correctly but I couldn't invoke it from my client side.I'm using Db2 database. Please help.

Here is my JavaScript code..

function loadDetails(x,y,z,a,b,c,d,e,f,g,h,i){

var x= document.getElementById("firstname").value;
var y= document.getElementById("lastname").value;
var z= document.getElementById("doorno").value;
var a= document.getElementById("streetname").value;

var b= document.getElementById("area").value;

var c= document.getElementById("zipcode").value;

var d= document.getElementById("landmark").value;

var e= document.getElementById("secques").value;

var f= document.getElementById("secans").value;

var g= document.getElementById("emailaddress").value;

var h= document.getElementById("username").value;

var i= document.getElementById("password").value;



var invocationData = {
        adapter : 'DBAdapter',
        procedure : 'addDBAdapter',
        parameters : [x,y,z,a,b,c,d,e,f,g,h,i]
    };

WL.Client.invokeProcedure(invocationData,{
    onSuccess : loadDetailsSuccess,
    onFailure : loadDetailsFailure

});

}

function loadDetailsSuccess(){

alert("Registration Successfull. Please login to continue...");
window.location.href = 'login.html';

}

function loadDetailsFailure(){

WL.Logger.error("load data failure");

}

DBAdapter-impl.js

var addStatement = WL.Server.createSQLStatement("insert into CUSTOMER(FIRSTNAME,LASTNAME,DOORNO,AREA,STREETNAME,ZIPCODE,LANDMARK,SECQUES,SECANS,EMAILADDRESS,USERNAME,PASSWORD) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)");

function addDBAdapter(x,y,z,a,b,c,d,e,f,g,h,i) {

return WL.Server.invokeSQLStatement({
    preparedStatement : addStatement,
    parameters : [x,y,z,a,b,c,d,e,f,g,h,i]
});

}

Was it helpful?

Solution

As eabe rightly so mention in the comments, and we've all missed it(!), Worklight is a Single Page Application and indeed window.location.href = 'login.html'; seems to be the culprit here.

See this related question on this subject matter that also contain solutions:

Basically, you can use either jQuery's .load or jQuery Mobile's .changePage (or the equivalent of other libraries to do the same) in order to load the contents of another page, or "switch" to another. Doing what you do, you lost the Worklight "context" and nothing will work or display.

Also review this training material:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top