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