Skip to content

Instantly share code, notes, and snippets.

Created March 20, 2019 04:03
What would you like to do?
Call to the Azure Cognitive Services Computer Vision API from JavaScript
// TODO: if needed, adapt the URL to the region where you created the service
url: "" + $.param(params),
beforeSend: function(xhrObj){
// Request the output formatted as JSON
// Send the subscription key as part of the header
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", subscriptionKey);
// Data is submitted to the server through a POST request
type: "POST",
// Request body: the image URL
data: '{"url": ' + '"' + sourceImageUrl + '"}',
.done(function(data) {
// Successful request: formate the result JSON in a human-friendly
// way and output it to the text area HTML element.
responseTextArea.val(JSON.stringify(data, null, 2));
.fail(function(jqXHR, textStatus, errorThrown) {
// Error: print the error message to the text area HTML element.
responseTextArea.val(JSON.stringify(jqXHR, null, 2));
alert("Request Failed");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment