1
votes

My node.js web-app is using microsoft's ocr computer vision api

https://www.microsoft.com/cognitive-services/en-us/computer-vision-api

When I pass a static link to the api, it works

like:

body: "{'url':'LINK_TO_IMAGE'}",

this is the part of the request callback.

What I want is to pass links dynamically.

So that the callback function is evoked the variable link

I have tried using this:

body: {'url':link},

but this does not work, there is no response.

Is there any other format I should follow?

1

1 Answers

0
votes

Look document, here https://dev.projectoxford.ai/docs/services/54ef139a49c3f70a50e79b7d/operations/5527970549c3f723cc5363e4

<!DOCTYPE html>
<html>
<head>
    <title>JSSample</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
            "language": "unk",
            "detectOrientation ": "true",
        };

        $.ajax({
            url: "https://api.projectoxford.ai/vision/v1/ocr?" + $.param(params),
            beforeSend: function(xhrObj){
                // Request headers
                xhrObj.setRequestHeader("Content-Type","application/json");
                xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","{subscription key}");
            },
            type: "POST",
            // Request body
            data: "{body}",
        })
        .done(function(data) {
            alert("success");
        })
        .fail(function() {
            alert("error");
        });
    });
</script>
</body>
</html>