2

I wanted to separate my main.js file from my sqlite function file. How can I get the result of the query to the main.js (fr anotherFile.js).

//In main.js
function getResult() {
    queryDB(); //how to get d result from queryDB() ?
}

 

// In anotherFile.js:
function queryDB(tx) {
    tx.executeSql('SELECT * FROM DEMO', [], onSuccess, onError);
}

function onSuccess(tx, results) {
    for (var i=0; i<result.length; i++) { 
        //what to put here, Array?
    }
}

thanks.

1 Answer 1

1
//anotherFile.js:

function queryDB(tx, callbackMethod) {
    tx.executeSql('SELECT * FROM DEMO', [], callbackMethod, onError);
}

//main.js

function sendQuery() {
    queryDB(tx, queryResult);
}

function queryResult(tx, results) {
    for (var i=0; i<result.length; i++) { 

    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the answer, i found out that i can just cut n paste any function into another file. It will works just fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.