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
    What kind of errors are you getting? Commented Jan 16, 2015 at 9:30
  • 1
    Maybe an XSS problem? Commented Jan 16, 2015 at 9:34
  • no error :( what is exactly Cross-Site Scripting issue? Commented Jan 16, 2015 at 9:56
  • 1
    Use Fiddler (telerik.com/fiddler), Developer Tools in your Browser (F12 in Chrome and Internet Explorer) or a hosted service like Runscope (runscope.com) to act as a debgging proxy to your API. I would start with your in-browser tools first and use the 'Network' tab to see what response the API HTTP calls return (anything in 400 / 500 response range isn't good). Commented Jan 16, 2015 at 9:59
  • @SimonW W thanks After F12 getting 200 status code with no data in request body :( Commented Jan 16, 2015 at 10:04

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.