|

14精币
def get_time_slots(date):
# 这里可以根据日期从数据库或其他数据源获取时间节点
# 目前模拟返回固定时间节点
return ["09:00", "10:00", "11:00", "14:00", "15:00"]
@app.route('/get_time_slots', methods=['GET'])
def get_time_slots_route():
date = request.args.get('date')
time_slots = get_time_slots(date)
return jsonify({'timeSlots': time_slots})
以上是AI写的用python返回给前端ajax内容,但是我后端用的易语言,想直接返回同样的文本内容给前端。易语言生成的内容应该是怎样的?我现在后端返回 {time_slots:["10:00", "11:00", "14:00"]"}是错误的。
以下是前端的ajax部分。我是想点击时间,get把日期传给易语言后端,后端再返回这个日期可用时间节点,比如["09:00", "10:00", "11:00", "14:00", "15:00"],然后前端time就可以选择时间节点。
// 监听日期选择变化事件
document.getElementById('date').addEventListener('change', function () {
const selectedDate = this.value;
const timeSelect = document.getElementById('time');
timeSelect.innerHTML = '<option value="">加载中...</option>';
timeSelect.disabled = true;
// 发送 AJAX 请求获取时间节点
fetch(`/get_time_slots?date=${selectedDate}`)
.then(response => response.json())
.then(data => {
console.log('后端返回的时间节点数组:', data.timeSlots);
timeSelect.innerHTML = '';
if (data.timeSlots.length === 0) {
timeSelect.innerHTML = '<option value="">无可用时间</option>';
} else {
data.timeSlots.forEach(time => {
const option = document.createElement('option');
option.value = time;
option.textContent = time;
timeSelect.appendChild(option);
});
}
timeSelect.disabled = false;
})
.catch(error => {
console.error('获取时间节点失败:', error);
timeSelect.innerHTML = '<option value="">获取时间失败</option>';
timeSelect.disabled = true;
});
});
|
最佳答案
查看完整内容
后端易语言直接返回这段文本:{"timeSlots":["09:00","10:00","11:00","14:00","15:00"]}
|