0

I'm having trouble inserting multiple records into an HTML5 Database. I verified the schema is properly being inserted.

Am I calling it in an invalid manner?

    // Ajax Call to Get Users function
    $.ajax({
        type: "POST",
        url: "Handlers/UserHandler.php",
        data: "method=getAllUsers",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
        success: function (data) {

            database.db.transaction(function (tx) {
                for (var id in data) {
                    tx.executeSql('INSERT INTO contacts(id, fname, lname, email, loginId) VALUES (?, ?, ?, ?, ?)', [id , data[id].FirstName, data[id].LastName, data[id].Email, data[id].LoginId]);
                }
            });
        }
    });

1 Answer 1

2

The database should be opened before executing any SQL inserts within the transaction. To open a connection to the database just call the function openDatabase to get the db object:

db = window.openDatabase(dbName<string>, dbVersion<string>, dbDescription<string>, dbSize<int>);

An optional 5h parameter is allowed, passing a callback function to be called after the database is created.

If the database was already opened, can you give more information about the error or behaviour you are obtaining?

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

Comments

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.