常见的Ajax请求:
let config= {
url: url,
type: type,
dataType: dataType,
data: data,
beforeSend: function () {
$.modal.loading(i18n('Processing.please.wait'));
},
success: function (result) {
if (result.code == "0") {
$.table.refresh();
}
}
};
$.ajax(config)
替代方式:fetch
try {
const response = await fetch(url, {
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json"
}
});
if (!response.ok) {
throw new Error(`服务器响应错误,状态码: ${response.status}`);
}
return await response.json();
} catch (error) {
// 处理网络错误或服务器问题
console.error(`请求失败: ${error.message}`);
}