Q:

How do I Add/combine my ajax call output to mysql insert query?

I am trying to retrieve data from one database using an ajax call then putting the data in an insert query so it can be added to the new database. (php mysql to phonegap local db). Here are my two codes that I need to combine. The ajax code is currently just outputting to a table, I did this just to see it was working. The javascript function does work and adds to the DB.
jQuery(document).ready(function(){

jQuery.ajax({
    url : "http://cmlsys/toby/fetchdata.php",
    type : "POST",
    dataType : "json",
    data : "param=no",
    success : function (html){

        jQuery.each(html, function(key, value){

        $("table#DOM").append('<tr><td>'+value.CurrencyCode+'</td></tr>');

        });

    }, error : function (e){

        alert(e);

    }

});

});

function getEmployees(tx) {
var sql = "select id, CurrencyCode " + "from employee";
tx.executeSql(sql, [], getEmployees_success);

}
function populateDB(tx) {
$('#busy').show();
tx.executeSql('DROP TABLE IF EXISTS employee');
var sql = 
    "CREATE TABLE IF NOT EXISTS employee ( "+
    "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
    "CurrencyCode VARCHAR(50))";

tx.executeSql(sql);

tx.executeSql("INSERT INTO employee (id,CurrencyCode) VALUES (1,'**THE AJAX RETURN**')");

}

Here is all of my code - 

var db;
var dbCreated = false;

var scroll = new iScroll('wrapper', { vScrollbar: false, hScrollbar:false, hScroll: false });

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    db = window.openDatabase("EmployeeDirectoryDB", "1.0", "PhoneGap Demo", 200000);
    if (dbCreated)
     db.transaction(getEmployees, transaction_error);
    else
     db.transaction(populateDB, transaction_error, populateDB_success);
}

function transaction_error(tx, error) {
 $('#busy').hide();
    alert("Database Error: " + error);
}

function populateDB_success() {
 dbCreated = true;
    db.transaction(getEmployees, transaction_error);
}


function getEmployees(tx) {
 var sql = "select id, CurrencyCode " + "from employee";
 tx.executeSql(sql, [], getEmployees_success);
}


function getEmployees_success(tx, results) {
 
 $('#busy').hide();
    var len = results.rows.length;
    for (var i=0; i<len; i++) {
     var employee = results.rows.item(i);

  $('#employeeList').append('<p class="line2">' + employee.CurrencyCode + '</p>');
    }
 
 setTimeout(function(){
  scroll.refresh();
 },100);
 db = null;
}



jQuery(document).ready(function () {
        jQuery.ajax({
            url: "http://cmlsys/toby/fetchdata.php",
            type: "POST",
            dataType: "json",
            data: "param=no",
            success: function (html) {                    
                populateDB(tx, html);
                getEmployees(tx);

            },
            error: function (e) {
                alert(e);
            }
        });
    });

    function populateDB(tx, html) {
        $('#busy').show();
        tx.executeSql('DROP TABLE IF EXISTS employee');
        var sql =
            "CREATE TABLE IF NOT EXISTS employee ( " +
            "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
            "CurrencyCode VARCHAR(50))";

        tx.executeSql(sql);
        var values = jQuery.map(html, function (val, i) {
            return "('" + val.CurrencyCode + "')";
        }).join(',');

        tx.executeSql("INSERT INTO employee (id,CurrencyCode) VALUES " + values);
    }

 
 

A:

You can pass your ajax success data to populateDB function in your success closure. Please check the code below. I guess your tx is a global variable.
    var db;
var dbCreated = false;

var scroll = new iScroll('wrapper', {
    vScrollbar: false,
    hScrollbar: false,
    hScroll: false
});

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    db = window.openDatabase("EmployeeDirectoryDB", "1.0", "PhoneGap Demo", 200000);
    if (dbCreated) db.transaction(getEmployees, transaction_error);
    else CallAjax();
}

function transaction_error(tx, error) {
    $('#busy').hide();
    alert("Database Error: " + error);
}

function populateDB_success() {
    dbCreated = true;
    db.transaction(getEmployees, transaction_error);
}

function getEmployees(tx) {
    var sql = "select id, CurrencyCode from employee";
    tx.executeSql(sql, [], getEmployees_success);
}

function getEmployees_success(tx, results) {

    $('#busy').hide();
    var len = results.rows.length;
    for (var i = 0; i < len; i++) {
        var employee = results.rows.item(i);

        $('#employeeList').append('<p class="line2">' + employee.CurrencyCode + '</p>');
    }

    setTimeout(function () {
        scroll.refresh();
    }, 100);
    db = null;
}

function CallAjax() {
    jQuery.ajax({
        url: "http://cmlsys/toby/fetchdata.php",
        type: "POST",
        dataType: "json",
        data: "param=no",
        success: function (html) {
            $('#busy').show();
            db.transaction(function (tx) {
                tx.executeSql('DROP TABLE IF EXISTS employee');
                var sql =
                    "CREATE TABLE IF NOT EXISTS employee ( " +
                    "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                    "CurrencyCode VARCHAR(50))";

                tx.executeSql(sql);
                var values = jQuery.map(html, function (val, i) {
                    return "('" + val.CurrencyCode + "')";
                }).join(',');

                tx.executeSql("INSERT INTO employee (id,CurrencyCode) VALUES " + values);
            }, transaction_error, populateDB_success);

        },
        error: function (e) {
            alert(e);
        }
    });
}

