Kirk Bollinger
Kirk Bollinger

Reputation: 11

Javascript write to AWS DynamoDB

I'm writing to dynamodb using javascript and the aws sdk. This is working but I want to display a thanks page after writing. Basically this is a registration page, user fills out some info and then hits a button. This write to dynamodb. The problem is when I add code to display another page then the write does not happen. As if the process to do the write ends before the write happens. I'm not sure is this the problem that I found searching that require sleeping, callbacks or a promise? thanks!

db.putItem(itemParams, function(err, data){
        if (err) {
            console.log(err);
        } else {
            console.log('Success');
        }

    });     
window.location.href = "thanks.html";

Upvotes: 1

Views: 62

Answers (1)

Khalid T.
Khalid T.

Reputation: 10547

You'll need to put the window.location.href = "thanks.html"; line inside the callback:

db.putItem(itemParams, function(err, data) {
    if (err) {
        console.log(err);
    } else {
        console.log('Success');
        window.location.href = "thanks.html";
    }
});

Upvotes: 1

Related Questions