fix: goals.html使用正确的block名称extra_js
This commit is contained in:
@@ -70,7 +70,7 @@
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
{% block extra_js %}
|
||||
{{ super() }}
|
||||
<script>
|
||||
const API_BASE = '/api/goals';
|
||||
@@ -99,24 +99,36 @@ async function loadGoals() {
|
||||
|
||||
// 保存目标
|
||||
async function saveGoal() {
|
||||
console.log('saveGoal called');
|
||||
const id = document.getElementById('goal-id').value;
|
||||
const name = document.getElementById('goal-name').value;
|
||||
const content = document.getElementById('goal-content').value;
|
||||
console.log('Form data:', {id, name, content});
|
||||
|
||||
if (!name) { alert('请输入目标名称'); return; }
|
||||
|
||||
const method = id ? 'PUT' : 'POST';
|
||||
const url = id ? `${API_BASE}/${id}` : API_BASE;
|
||||
console.log('Sending to:', url, 'method:', method);
|
||||
|
||||
const res = await fetch(url, {
|
||||
method,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({name, content})
|
||||
});
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({name, content})
|
||||
});
|
||||
console.log('Response status:', res.status);
|
||||
|
||||
if (res.ok) {
|
||||
bootstrap.Modal.getInstance(document.getElementById('goalModal')).hide();
|
||||
loadGoals();
|
||||
if (res.ok) {
|
||||
bootstrap.Modal.getInstance(document.getElementById('goalModal')).hide();
|
||||
loadGoals();
|
||||
} else {
|
||||
const err = await res.json();
|
||||
alert(err.error || '保存失败');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Fetch error:', e);
|
||||
alert('网络错误: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user