我的网站按钮没有返回结果

问题描述 投票:0回答:1

我的网站https://frankydesigns.net/我创建时遇到一些困难。保存个人资料和显示员工按钮不会产生结果。我过去常常遇到一堆错误并修复了这些错误,但现在我在保存个人资料时收到未定义的错误,并且显示员工没有响应。

我正在使用 aws,因此我的网页应该将用户输入的保存配置文件数据上传到我的 dynamoDB 表中,当用户单击“显示员工”时,它应该显示结果。

如有任何建议,我们将不胜感激。下面是我的 Java 和 Python 脚本

我的Java脚本

function saveProfile() {
    const employeeId = document.getElementById('employeeId').value;
    const firstName = document.getElementById('firstName').value;
    const lastName = document.getElementById('lastName').value;
    const age = document.getElementById('age').value;

    const data = {
        employeeId,
        firstName,
        lastName,
        age
    };

    fetch('https://hfs2p8upk2.execute-api.us-east-2.amazonaws.com/project/', {
            method: 'POST',
            mode: "cors",
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(data)
        })
        .then(response => response.json())
        .then(result => alert(result.message))
        .catch(error => console.error('Error:', error));
}

function showEmployees() {
    fetch('https://hfs2p8upk2.execute-api.us-east-2.amazonaws.com/project/')
        .then(response => response.json())
        .then(profiles => {
            const employeeList = document.getElementById('employeeList');
            employeeList.innerHTML = '';

            profiles.forEach(profile => {
                const employeeInfo = document.createElement('div');
                employeeInfo.innerHTML = `<strong>Employee ID:</strong> ${profile.employeeId}, <strong>Name:</strong> ${profile.firstName} ${profile.lastName}, <strong>Age:</strong> ${profile.age}`;
                employeeList.appendChild(employeeInfo);
            });
        })
        .catch(error => console.error('Error:', error));
}

Python 脚本

from flask import Flask, request, jsonify
from flask_cors import CORS
import boto3

app = Flask(__name__)
CORS(app)

# DynamoDB Configuration
dynamodb = boto3.resource('tablefranky')
table = dynamodb.Table('tablefranky')  

@app.route('/save_profile', methods=['POST'])
def save_profile():
    data = request.json
    table.put_item(Item=data)
    return jsonify({'message': 'Profile saved successfully'})

@app.route('/get_profiles', methods=['GET'])
def get_profiles():
    response = table.scan()
    profiles = response.get('Items', [])
    return jsonify(profiles)

if __name__ == '__main__':
    app.run(debug=True)
javascript python amazon-dynamodb
1个回答
0
投票

您将因不提供您所看到的错误日志而关闭您的问题。在支持您的网站之前,您是否测试过您的代码,因为它似乎没有。

这是在 boto3 中创建 DynamoDB 资源的方式

import boto3

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('tablefranky')

这是您的第一个错误,可能还有无数个错误。在尝试集成前端之前,测试您的 DynamoDB API。

© www.soinside.com 2019 - 2024. All rights reserved.