2

I wanted to know if there is a way to call the Azure Machine Learning webservice using JavaScript Ajax.

The Azure ML gives sample code for C#, Python and R.

I did try out to call the webservice using JQuery Ajax but it returns a failure.

I am able to call the same service using a python script.

Here is my Ajax code :

  $.ajax({
        url: webserviceurl,
        type: "POST",           
        data: sampleData,            
        dataType:'jsonp',                        
        headers: {
        "Content-Type":"application/json",            
        "Authorization":"Bearer " + apiKey                       
        },
        success: function (data) {
          console.log('Success');
        },
        error: function (data) {
           console.log('Failure ' +  data.statusText + " " + data.status);
        },
  });
2
  • What failure does it return? You're looking at the statusText and the status. What do they say? Does the console display any errors? If you pay attention to the second and third arguments of the error function, do they say anything useful? What does the Network tab of your browser's developer tools say? Is the request being made? Does it get a response? Commented May 25, 2016 at 18:37
  • I get error 404. After researching some more I found out that CORS is not supported by Azure ML. link . Commented May 25, 2016 at 18:55

3 Answers 3

3

It doesn't work due to CORS not enabled on Azure ML web services. You can wrap Azure ML web service using Azure API management which can be called from JavaScript - https://azure.microsoft.com/en-us/documentation/articles/api-management-get-started/

Sign up to request clarification or add additional context in comments.

Comments

2

Well after a lot of RnD, I was able to finally call Azure ML using some workarounds.

Wrapping Azure ML webservice on Azure API is one option.

But, what I did was that I created a python webservice which calls the Azure webservice.

So now my HTML App calls the python webservice which calls Azure ML and returns data to the HTML App.

Comments

0

Per my experience, it seems to be caused by the timeout, so I think you can try to refer to the answer for the SO thread Set timeout for ajax (jQuery) to set the timeout for the ajax request.

Hope it help.


There is an answered SO thread Azure Machine Learning - CORS which is similar with your issue. I think it's helpful, please try.

3 Comments

I did give it a try but I don't think that is a real issue. At first I was getting CORS error, to resolve this I added datatype as jsonp. Now I am getting a 404 error code. Is there anything which can be done from Azure ML web service setting?
@Tilak Hi, I updated my post, please try. And any update, please feel free to let me know.
@PeterSmith Yes..that is what I figured out that Azure ML does not support CORS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.