-1

I am trying to develop mobile application and I use the framework (PhoneGap), I have sql operation so I choose this separate, and each operation put under a function and these functions will be called in order.

my problem that these functions are not calling in order

2 Answers2

3

JavaScript SQL libraries tend to be asynchronous and use callbacks. Put the call to the next function in the callback you use in the previous function.

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205
0

Javascript code is generally asynchronous, to ensure code execution order generally callbacks are used, a function in a library may look like this:

function doWork(params, callback){
  //do stuff

  //when done call the callback function
  callback()
}

This allows you to use this function and pass a function to be called when this function has finished doing what it needs to do.

doWork(params, function() { 
  //this code is not executed until doWork has completed and called its callback 
})

Have a look at the library you are using they probably use callbacks

Declan Cook
  • 5,809
  • 2
  • 33
  • 51