1

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";

1 Answer 1

1

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";
    }
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that took care of it.

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.