-1

我想使用 JavaScript 从 Azure Custom Vision 模型接收判断结果。

我更改了该站点的 JavaScript 代码。

https://southcentralus.dev.cognitive.microsoft.com/docs/services/eb68250e4e954d9bae0c2650db79c653/operations/58acd3c1ef062f0344a42814

但我不能。我的代码有什么问题?

我更改了 IterationId、application、url、content-Type、Prediction-key 和 data。

这些部分在下面的代码中用 {} 括起来。

<!DOCTYPE html>
<html>
<head>
    <title>Human</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"> 
</script>
</head>
<body>

<script type="text/javascript">
$(function() {
    var params = {
        // Request parameters
        "iterationId": "{Iteration id that showed in Performance Page}",
        "application": "{My Project name of Custom Vision}",
    };

    $.ajax({
        url: "{url that showed in "How to use the Prediction API"}" + $.param(params),
        beforeSend: function(xhrObj){
            // Request headers
            xhrObj.setRequestHeader("Content-Type","application/octet-stream");
            xhrObj.setRequestHeader("Prediction-key","{my prediction key that showed in "How to use the Prediction API"}");
        },
        type: "POST",
        // Request body
        data: "D:\some name\some name\image.jpg",
    })
    .done(function(data) {
        alert("success");
    })
    .fail(function() {
        alert("error");
    });
});
</script>
</body>
</html>

当然,我希望展示“成功”。

但是,实际输出是“错误”......

4

2 回答 2

0

更改代码以查看返回的错误是什么:

(注意请求的新“错误”参数)

$.ajax({
    url: "{url that showed in "How to use the Prediction API"}" + $.param(params),
    beforeSend: function(xhrObj){
        // Request headers
        xhrObj.setRequestHeader("Content-Type","application/octet-stream");
        xhrObj.setRequestHeader("Prediction-key","{my prediction key that showed in "How to use the Prediction API"}");
    },
    type: "POST",
    // Request body
    data: "D:\some name\some name\image.jpg",
    error: function(xhr,status,error) {
        // >>>>>>>>>>>> CHECK HERE THE ERROR <<<<<<<<<<<<
    }
})
.done(function(data) {
    alert("success");
})
.fail(function() {
    alert("error");
});

一旦你有错误,它会更容易帮助你。

于 2019-08-17T07:39:52.397 回答
0

当我在我的代码中更改此站点具有的 URL(https://southcentralus.dev.cognitive.microsoft.com/docs/services/eb68250e4e954d9bae0c2650db79c653/operations/58acd3c1ef062f0344a42814)时,我可以收到成功消息。而且,我还在代码中用 ajax 编写了 processData: false, contentType: false,

于 2019-08-16T17:19:46.600 回答