请合并以下两个函数 async function sendBoxcoordinates(mainImage, x_topleft, y_topleft, x_rightdown, y_rightdown) { const payload = { x_topleft: x_topleft, y_topleft: y_topleft, x_rightdown: x_rightdown, y_rightdown: y_rightdown, image_url: mainImage.src, ctrl: ctrlPressed ? 0 : 1 // 如果ctrl键被按下,将参数设置为-1,否则为1 }; const response = await fetch('/api/coordinates', { // 修改为实际API地址 method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) });
时间: 2024-04-18 11:33:45 浏览: 76
async function sendBoxcoordinates(mainImage, x_topleft, y_topleft, x_rightdown, y_rightdown) {
const payload = {
x_topleft: x_topleft,
y_t: y_topleft,
x_rightdown:_rightdown,
y_rightdown: y_rightdown,
image_url: mainImage.src,
ctrl: ctrlPressed ? 0 : 1 // 如果ctrl键被按下,将参数设置为-1,否则为1
};
const response = await postData('/api/coordinates', payload); // 使用新函数postData发送POST请求
// 处理response的逻辑
}
async function postData(url, data) {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
return response;
}
阅读全文