正如我在标题中所描述的,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);
}
},
});
}
拉莫斯之舞
相关分类