对于这个问题,我几乎没有在 stackoverflow 上留下任何疑虑。 基本上我正在做的是在后端向我的 MachineLearning 模型 发送 ajax 请求中的图片,该模型会进行一些计算,并根据该计算回复我两个答案是或否。就是这样。问题可能是超时或图像未正确发送。模型几乎需要 6 - 8 秒 来运行并生成结果。 我用过 jquery 的这一行:
$("#image").attr("src")
要从 img 标签中选择图像,它会以字符串形式提供图像。可能有问题,也可能没有。
但是我在后端对我的模型的 ajax 请求看起来像这样:
var src = $(#image).attr("src");
var form = new FormData();
form.append("file", src);
var token = localStorage.getItem('token');
var Calculate= {
"async": true,
"crossDomain": true,
"url": "http://xx.xxx.xxx.xxx/predictor",
"method": "POST",
"headers": {
"x-access-token": token,
"Accept": "*/*",
"Cache-Control": "no-cache",
"Host": "xx.xxx.xxx",
"Content-Type": "multipart/form-data;
"cache-control": "no-cache"
},
"processData": false,
"contentType": false,
"mimeType": "multipart/form-data",
"data": form
}
$.ajax(Calculate).done(function (response) {
setTimeOut(console.log(response),8000);
});
最佳答案
试试这段代码:
$.ajax(Calculate).done(function (response) {
setTimeout(function() {console.log(response);}, 8000);
});
关于javascript - AJAX 请求图像不使用 jquery 发送/响应超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58483616/