1

I'm working on API management and exposing API using Javascript code If I go to Developer portal and check my url it gives me correct result like below

Response content
[{
"ContactId":1,
"Name":"Debra Garcia",
"Address":"1234 Main St",
},

{"ContactId":2,
"Name":"Thorsten Weinrich",
"Address":"5678 1st Ave W",
}]

but using javascript code I'm not getting anything Nor status error code :(
Js Code
<script type="text/javascript">
    $(function() {
        var params = {

            'subscription-key': 'mykey',
        };

        $.ajax({
            url: 'https://mydemo.azure-api.net/marketing/contacts?' + $.param(params),
            type: 'GET',
        })
        .done(function(data) {
            alert("success");
        })
        .fail(function() {
            alert("error");
        });
    });
</script>

Where I need to debug? enter image description here

5

1 Answer 1

2

Make sure that you have enabled CORS support on your API using the correct policy. The Azure documentation site has an example of how to do this (snippet below):

<cors>
    <allowed-origins>
        <origin>*</origin> <!-- allow any -->
        <!-- OR a list of one or more specific URIs (case-sensitive) -->
        <origin>http://contoso.com:81</origin> <!-- URI must include scheme, host, and port. If port is omitted, 80 is assumed for http and 443 is assumed for https. -->
    </allowed-origins>
</cors>
Sign up to request clarification or add additional context in comments.

2 Comments

Where exactly I need to configure :O I have installed this Install-Package Microsoft.AspNet.WebApi.Cors
This policy is added via the Publisher Portal for Azure API Management.

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.