-1

I want to receive judgement result from model of Azure Custom Vision by using JavaScript.

I changed JavaScript code that this site has.

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

But I can't. What is wrong with my code?

I changed IterationId, application, url, content-Type, Prediction-key, and data.

These part are enclosed with {} in the code below.

<!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>

Of course, I expected showing "success".

But, the actual output is "error"......

2 Answers2

0

When I changed URL that this site has(https://southcentralus.dev.cognitive.microsoft.com/docs/services/eb68250e4e954d9bae0c2650db79c653/operations/58acd3c1ef062f0344a42814) in my code, I can get Success message. And, I also write processData: false, contentType: false, in ajax in my code

0

Change your code to see what is the error that you get back:

(Note the new "error" parameter to the request)

$.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");
});

Once you have the error, it would be easier to help you.

Alex Pshul
  • 694
  • 3
  • 11