简体   繁体   English

Javascript 写入 AWS DynamoDB

[英]Javascript write to AWS DynamoDB

I'm writing to dynamodb using javascript and the aws sdk.我正在使用 javascript 和 aws sdk 写信给 dynamodb。 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.这将写入 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";

You'll need to put the window.location.href = "thanks.html";你需要把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";
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM