正如我在标题中所描述的,ajax 同时发送两个请求。仅当“async”参数设置为“true”时才会发生这种情况。当它是“false”时,就没有问题。我正在阻止通过以下方式重新加载页面:$(document).ready(function() {$(document).on('submit', 'form', function() { showBusyIndicator(); addTask(); return false;});这是函数 addTask():function addTask() {let newTask = new Task( $("#taskSummary").val(), $("#taskDescription").val(), $("#taskDueTo").val());$.ajax({ url: apiHost + "/task/add/", headers: { "contentType": "application/json" }, type: "POST", async: true, dataType: "json", data: JSON.stringify(newTask), complete: function (xhr) { hideBusyIndicator(); if (xhr.status === 201) { closeAddTaskForm(); } else { alert(xhr.status); } },});}
1 回答

拉莫斯之舞
TA贡献1820条经验 获得超10个赞
发现问题 - 感谢@Randy Casburn。
addTask 的调用都在 $(document).on('submit', 'form', function()
并且也在 <form onsubmit="addTask()">
添加回答
举报
0/150
提交
取消