对于这个问题,我几乎没有给堆积如山留下任何困难。基本上,我所做的是将ajax请求中的图片发送给后端的MachineLearning model,它进行了一些计算,并在此计算的基础上回答了两个答案:是或否。就这样。问题可能是超时或图像发送不正确。模型几乎需要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);
});发布于 2019-10-21 10:25:06
试试下面的代码:
$.ajax(Calculate).done(function (response) {
setTimeout(function() {console.log(response);}, 8000);
});https://stackoverflow.com/questions/58483616
复制相似问题